Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: Questions on matrix operations (inverse) and mvnrnd

Subject: Questions on matrix operations (inverse) and mvnrnd

From: Ycshmily M

Date: 16 Jul, 2008 20:05:30

Message: 1 of 7

Hello Matlab users,

I have questions on matrix operations and appreciate some
help.

First, I need to inverse an n by n symmetric matrix H,
which is certainly not singular. Since I would receive a
warning message as 'Matrix is close to singular or badly
scaled', if I would use 'inv(H)'. Thus I have tried four
alternatives respectively as follows.
(A) Hinv = H\eye(n);
(B) Hinv = linsolve(H, eye(n));
(C) temp = chol(H)\eye(n); Hinv=temp*temp';
(D) Hinv = pinv(H).
I still received warning messages on singularity in the
first two cases (A) and (B). Although I did not receive any
warning messages in the last two cases (C) and (D), the
results do not appear to be accurate enough to pass some
tests.

Second, I need to use 'mvnrnd(MU, SIGMA)' to obtain random
vectors. The covariance matrix SIGMA in my case is
specified as the inverse of H denoted as Hinv. Although
Hinv looks like a symmetric matrix in an array editor,
Matlab returns an error message as 'SIGMA must be a
symmetric positive semi-definite matrix'. Thus I have tried
an althernative:
sigma = Hinv-(Hinv-Hinv')./2.
Then, I will not receive error messages.

In short, I wanted to know how to effectively
(1) obtian the inverse of an n by n matrix H (denote it as
Hinv);
(2) use mvnrnd(MU, SIGMA) by setting SIGMA equal to Hiv;
without receiving warning/error messages.

Thank you very much!

Ycshmily.

Subject: Re: Questions on matrix operations (inverse) and mvnrnd

From: Peter Perkins

Date: 17 Jul, 2008 12:50:38

Message: 2 of 7

Ycshmily M wrote:

> First, I need to inverse an n by n symmetric matrix H,
> which is certainly not singular. Since I would receive a
> warning message as 'Matrix is close to singular or badly
> scaled'

Ycshmily, apparently H _is_ singular, or at least it is "numerically singular",
meaning that it is so close to being singular that any numerical operations
(such as inversion) are doomed to be unstable.

, if I would use 'inv(H)'. Thus I have tried four
> alternatives respectively as follows.
> (A) Hinv = H\eye(n);
> (B) Hinv = linsolve(H, eye(n));
> (C) temp = chol(H)\eye(n); Hinv=temp*temp';
> (D) Hinv = pinv(H).
> I still received warning messages on singularity in the
> first two cases (A) and (B). Although I did not receive any
> warning messages in the last two cases (C) and (D), the
> results do not appear to be accurate enough to pass some
> tests.
>
> Second, I need to use 'mvnrnd(MU, SIGMA)' to obtain random
> vectors. The covariance matrix SIGMA in my case is
> specified as the inverse of H denoted as Hinv. Although
> Hinv looks like a symmetric matrix in an array editor,
> Matlab returns an error message as 'SIGMA must be a
> symmetric positive semi-definite matrix'.

You may be giving MVNRND a matrix that is not symmetric, but based on your
earlier comments, it may also be that it is not (numerically) positive
semi-definite. Set a break point in MVNRND (or CHOLCOV) and find out why it is
erroring out.

Hope this helps.

Subject: Re: Questions on matrix operations (inverse) and mvnrnd

From: Ycshmily M

Date: 17 Jul, 2008 14:57:02

Message: 3 of 7

Hello Peter,

Thanks for your reply!

In my case, the H matrix is a large (could be 400 by 400)
sparse matrix, which I suspect could be a reason for those
warning/error messages because the way Matlab handles
sparse matrices. Therefore, I am looking for some effective
transformations to circumvent the problem, like using
Cholesky decomposition at first and then taking the
inverse...

Ycshmily.

Peter Perkins <Peter.PerkinsRemoveThis@mathworks.com> wrote
in message <g5nf6u$15b$1@fred.mathworks.com>...
> Ycshmily M wrote:
>
> > First, I need to inverse an n by n symmetric matrix H,
> > which is certainly not singular. Since I would receive
a
> > warning message as 'Matrix is close to singular or
badly
> > scaled'
>
> Ycshmily, apparently H _is_ singular, or at least it
is "numerically singular",
> meaning that it is so close to being singular that any
numerical operations
> (such as inversion) are doomed to be unstable.
>
> , if I would use 'inv(H)'. Thus I have tried four
> > alternatives respectively as follows.
> > (A) Hinv = H\eye(n);
> > (B) Hinv = linsolve(H, eye(n));
> > (C) temp = chol(H)\eye(n); Hinv=temp*temp';
> > (D) Hinv = pinv(H).
> > I still received warning messages on singularity in the
> > first two cases (A) and (B). Although I did not receive
any
> > warning messages in the last two cases (C) and (D), the
> > results do not appear to be accurate enough to pass
some
> > tests.
> >
> > Second, I need to use 'mvnrnd(MU, SIGMA)' to obtain
random
> > vectors. The covariance matrix SIGMA in my case is
> > specified as the inverse of H denoted as Hinv. Although
> > Hinv looks like a symmetric matrix in an array editor,
> > Matlab returns an error message as 'SIGMA must be a
> > symmetric positive semi-definite matrix'.
>
> You may be giving MVNRND a matrix that is not symmetric,
but based on your
> earlier comments, it may also be that it is not
(numerically) positive
> semi-definite. Set a break point in MVNRND (or CHOLCOV)
and find out why it is
> erroring out.
>
> Hope this helps.

Subject: Re: Questions on matrix operations (inverse) and mvnrnd

From: Tim Davis

Date: 18 Jul, 2008 10:59:02

Message: 4 of 7

"Ycshmily M" <ycshmily@yahoo.com> wrote in message
<g5nmju$64o$1@fred.mathworks.com>...
> Hello Peter,
>
> Thanks for your reply!
>
> In my case, the H matrix is a large (could be 400 by 400)
> sparse matrix, which I suspect could be a reason for those
> warning/error messages because the way Matlab handles
> sparse matrices. Therefore, I am looking for some effective
> transformations to circumvent the problem, like using
> Cholesky decomposition at first and then taking the
> inverse...
>
> Ycshmily.

That's what inv does in the sparse case, I think.

Do you really truly need the inverse? What are you doing
with the inverse?

You might also try pinv(full(A)), since A is small (only
400-by-400). The pseudo inverse always exists, whether or
not A is singular.

Subject: Re: Questions on matrix operations (inverse) and mvnrnd

From: Peter Perkins

Date: 17 Jul, 2008 12:50:38

Message: 5 of 7

Ycshmily M wrote:

> First, I need to inverse an n by n symmetric matrix H,
> which is certainly not singular. Since I would receive a
> warning message as 'Matrix is close to singular or badly
> scaled'

Ycshmily, apparently H _is_ singular, or at least it is "numerically singular",
meaning that it is so close to being singular that any numerical operations
(such as inversion) are doomed to be unstable.

, if I would use 'inv(H)'. Thus I have tried four
> alternatives respectively as follows.
> (A) Hinv = H\eye(n);
> (B) Hinv = linsolve(H, eye(n));
> (C) temp = chol(H)\eye(n); Hinv=temp*temp';
> (D) Hinv = pinv(H).
> I still received warning messages on singularity in the
> first two cases (A) and (B). Although I did not receive any
> warning messages in the last two cases (C) and (D), the
> results do not appear to be accurate enough to pass some
> tests.
>
> Second, I need to use 'mvnrnd(MU, SIGMA)' to obtain random
> vectors. The covariance matrix SIGMA in my case is
> specified as the inverse of H denoted as Hinv. Although
> Hinv looks like a symmetric matrix in an array editor,
> Matlab returns an error message as 'SIGMA must be a
> symmetric positive semi-definite matrix'.

You may be giving MVNRND a matrix that is not symmetric, but based on your
earlier comments, it may also be that it is not (numerically) positive
semi-definite. Set a break point in MVNRND (or CHOLCOV) and find out why it is
erroring out.

Hope this helps.

Subject: Re: Questions on matrix operations (inverse) and mvnrnd

From: Ycshmily M

Date: 17 Jul, 2008 14:57:02

Message: 6 of 7

Hello Peter,

Thanks for your reply!

In my case, the H matrix is a large (could be 400 by 400)
sparse matrix, which I suspect could be a reason for those
warning/error messages because the way Matlab handles
sparse matrices. Therefore, I am looking for some effective
transformations to circumvent the problem, like using
Cholesky decomposition at first and then taking the
inverse...

Ycshmily.

Peter Perkins <Peter.PerkinsRemoveThis@mathworks.com> wrote
in message <g5nf6u$15b$1@fred.mathworks.com>...
> Ycshmily M wrote:
>
> > First, I need to inverse an n by n symmetric matrix H,
> > which is certainly not singular. Since I would receive
a
> > warning message as 'Matrix is close to singular or
badly
> > scaled'
>
> Ycshmily, apparently H _is_ singular, or at least it
is "numerically singular",
> meaning that it is so close to being singular that any
numerical operations
> (such as inversion) are doomed to be unstable.
>
> , if I would use 'inv(H)'. Thus I have tried four
> > alternatives respectively as follows.
> > (A) Hinv = H\eye(n);
> > (B) Hinv = linsolve(H, eye(n));
> > (C) temp = chol(H)\eye(n); Hinv=temp*temp';
> > (D) Hinv = pinv(H).
> > I still received warning messages on singularity in the
> > first two cases (A) and (B). Although I did not receive
any
> > warning messages in the last two cases (C) and (D), the
> > results do not appear to be accurate enough to pass
some
> > tests.
> >
> > Second, I need to use 'mvnrnd(MU, SIGMA)' to obtain
random
> > vectors. The covariance matrix SIGMA in my case is
> > specified as the inverse of H denoted as Hinv. Although
> > Hinv looks like a symmetric matrix in an array editor,
> > Matlab returns an error message as 'SIGMA must be a
> > symmetric positive semi-definite matrix'.
>
> You may be giving MVNRND a matrix that is not symmetric,
but based on your
> earlier comments, it may also be that it is not
(numerically) positive
> semi-definite. Set a break point in MVNRND (or CHOLCOV)
and find out why it is
> erroring out.
>
> Hope this helps.

Subject: Re: Questions on matrix operations (inverse) and mvnrnd

From: Tim Davis

Date: 18 Jul, 2008 10:59:02

Message: 7 of 7

"Ycshmily M" <ycshmily@yahoo.com> wrote in message
<g5nmju$64o$1@fred.mathworks.com>...
> Hello Peter,
>
> Thanks for your reply!
>
> In my case, the H matrix is a large (could be 400 by 400)
> sparse matrix, which I suspect could be a reason for those
> warning/error messages because the way Matlab handles
> sparse matrices. Therefore, I am looking for some effective
> transformations to circumvent the problem, like using
> Cholesky decomposition at first and then taking the
> inverse...
>
> Ycshmily.

That's what inv does in the sparse case, I think.

Do you really truly need the inverse? What are you doing
with the inverse?

You might also try pinv(full(A)), since A is small (only
400-by-400). The pseudo inverse always exists, whether or
not A is singular.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
matrix inverse singular mvnrnd symmetric Ycshmily M 16 Jul, 2008 16:10:08
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics