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

Thread Subject: checki if a matrix is positive-semidefinite

Subject: checki if a matrix is positive-semidefinite

From: deluded.soul@gmail.com

Date: 05 Jan, 2008 00:15:25

Message: 1 of 6

Hi everyone,

How can I check if a given square matrix is positive-semidefinite in
Matlab?

Cheers,
D

Subject: Re: checki if a matrix is positive-semidefinite

From: Roger Stafford

Date: 05 Jan, 2008 00:57:55

Message: 2 of 6

"deluded.soul@gmail.com" <deluded.soul@gmail.com> wrote in message
<21285762-825c-4d9b-8323-6e9e65fe1cfc@j78g2000hsd.googlegroups.com
>...
> How can I check if a given square matrix is positive-semidefinite in
> Matlab?
-----------
  The matrix, A, is positive semidefinite if all the eigenvalues of its Hermitian
part, (A+A')/2, are non-negative.

Roger Stafford

Subject: Re: checki if a matrix is positive-semidefinite

From: deluded.soul@gmail.com

Date: 05 Jan, 2008 01:11:00

Message: 3 of 6

On Jan 5, 12:57 am, "Roger Stafford"
<ellieandrogerxy...@mindspring.com.invalid> wrote:
> "deluded.s...@gmail.com" <deluded.s...@gmail.com> wrote in message
>
> <21285762-825c-4d9b-8323-6e9e65fe1...@j78g2000hsd.googlegroups.com>...
> > How can I check if a given square matrix is positive-semidefinite in
> > Matlab?
>
> -----------
> The matrix, A, is positive semidefinite if all the eigenvalues of its Hermitian
> part, (A+A')/2, are non-negative.
>
> Roger Stafford


Hi Roger,

Thanks for the reply. So, if the matrix is only composed of real
elements than it is positive definite if all the eigenvalues are non-
negative?

The reason I ask is because I have the following matrices which has
all positive eigenvalues:

0.0017 -0.0000 -0.0002
-0.0000 0.0005 0.0000
-0.0002 0.0000 0.0006

The eigenvalues are:

 0.0005 0 0
      0 0.0006 0
      0 0 0.0017

Now, I expected the svd and eigenvalue decomposition to be the same
for this matrix. The singular values and eigenvalues are indeed the
same:

However, the svd returns the following "U" matrix.

0.4051 0.8347 0.3732
-0.8868 0.4580 -0.0620
-0.2227 -0.3058 0.9257

The eigenvalue returns the following eigenvectors (they are sorted
differently than the svd)
0.4051 0.3732 -0.8347
-0.8868 -0.0620 -0.4580
-0.2227 0.9257 0.3058

As you can see one of the vectors is in the different direction and I
am trying to figure out why they do not coincide.

Any ideas?

Thanks again!

D

Subject: Re: checki if a matrix is positive-semidefinite

From: Roger Stafford

Date: 05 Jan, 2008 05:33:46

Message: 4 of 6

"deluded.soul@gmail.com" <deluded.soul@gmail.com> wrote in message
<8c80ce68-a0d3-4c1d-
b3d3-3ff39f9ba7ee@c4g2000hsg.googlegroups.com>...
> Thanks for the reply. So, if the matrix is only composed of real
> elements than it is positive definite if all the eigenvalues are non-
> negative?
>
> The reason I ask is because I have the following matrices which has
> all positive eigenvalues:
>
> 0.0017 -0.0000 -0.0002
> -0.0000 0.0005 0.0000
> -0.0002 0.0000 0.0006
>
> The eigenvalues are:
>
> 0.0005 0 0
> 0 0.0006 0
> 0 0 0.0017
>
> Now, I expected the svd and eigenvalue decomposition to be the same
> for this matrix. The singular values and eigenvalues are indeed the
> same:
>
> However, the svd returns the following "U" matrix.
>
> 0.4051 0.8347 0.3732
> -0.8868 0.4580 -0.0620
> -0.2227 -0.3058 0.9257
>
> The eigenvalue returns the following eigenvectors (they are sorted
> differently than the svd)
> 0.4051 0.3732 -0.8347
> -0.8868 -0.0620 -0.4580
> -0.2227 0.9257 0.3058
>
> As you can see one of the vectors is in the different direction and I
> am trying to figure out why they do not coincide.
>
> Any ideas?
>
> Thanks again!
>
> D
--------
  Corresponding eigenvectors obtained by 'eig' and 'svd' will not necessarily
be in the same direction. Some of them can well be in opposite directions. In
fact, for complex-valued eigenvectors, they may differ by a complex scalar
factor which has a modulus of one. There is no canonical (preferred)
direction which can be uniquely defined for eigenvectors. The results all
depend on the details of the particular algorithm used to determine them.

  As for the singular values obtained with 'svd', as compared with the
eigenvalues from 'eig', they will not in general be the same unless the original
matrix is positive semidefinite. Singular values are always non-negative, but
eigenvalues can easily be negative or even complex-valued.

  Matlab's 'svd' always places the singular values in descending sequence, but
there is no guarantee as to order in the eigenvalue/eigenvector sequencing
obtained with 'eig'. This is undoubtedly due to the fact that sorting complex-
valued eigenvalues would be more or less meaningless. The particular
ordering received from an eigenvector routine is dependent on the methods
used by the algorithm designer.

Roger Stafford

Subject: Re: checki if a matrix is positive-semidefinite

From: Roger Stafford

Date: 05 Jan, 2008 05:44:14

Message: 5 of 6

  Oops! My apologies for accidentally clicking on the "Flag as spam" line instead
of the "View original format" line just above it on this thread. If anyone knows
how to undo this unintended action please do so.

Roger Stafford

Subject: Re: checki if a matrix is positive-semidefinite

From: John D'Errico

Date: 05 Jan, 2008 09:50:55

Message: 6 of 6

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in
message <fln5fe$rhk$1@fred.mathworks.com>...
> Oops! My apologies for accidentally clicking on the "Flag as spam" line
instead
> of the "View original format" line just above it on this thread. If anyone
knows
> how to undo this unintended action please do so.
>
> Roger Stafford

I did it once by accident too. I ended up
flagging enough posts as spam on one day
that it became a reflex action. So when I
went up there to respond to a post, I flagged
it instead.

You can't undo it. But the good news is, that
does not matter. You hurt nothing by your
mis-click. Since it takes 5 DIFFERENT people
to flag something as spam, only multiple
people making the same mistake as you do
will cause the post to go away. And the
probability of many people all mis-clicking
on the same post is quite small. This is the
wisdom of their choice to force multiple
people to flag a post as spam.

And, in the very rare event of a post
disappearing by such a compound mistake,
I imagine that an e-mail to our friendly
Matlab Central administrator would resolve
the problem.

One thing that could be done is to propose
to their team that they change the "flag as
spam" link to a flag as spam checkbox, that
can then be unchecked. It seems to me a
simple enough change that they might swap
it in on some upgrade to the site. I'm not at
all sure it is necessary though.

John

Tags for this Thread

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.

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