I need to generate a 3x3 positive semi-definite matrix but I don't
know what MATLAB function can do this?
Or is there any method to generate without try & check method?
Also, do you know what MATLAB function can be used to check if a
matrix is a positive semi-definite matrix?
Thank you
One way to generate a random positive semi-definite 3x3 matrix:
a = rand(3,3)
ata = a'*a
To check, use the eig function to see that all of the eigenvalues are
non-negative
eig(ata)
James Tursa
A = randn(3);
[U,ignore] = eig((A+A')/2); % (Don't really have to divide by 2)
M = U*diag(abs(randn(3,1)))*U';
Then M is a randomly determined positive semi-definite matrix.
2. Check that M is positive semi-definite:
all(diag(eig((M+M')/2))) >= 0
If this is true, then M is positive semi-definite
Roger Stafford
Clarify: "ata" is the positive semi-definite matrix, not "a".
all(eig((M+M')/2)) >= 0
I forgot that eig with only one output produces a vector result, not a square
array, and the diag operation should not be used.
Second observation: There seem to be two definitions of a semi-definite
matrix floating around. One, as for example in Wikipedia, insists that it both
be Hermitian and have non-negative eigenvalues. The other definition, as for
example in MathWorld and which I have used here, requires only that its
Hermitian part, (M+M')/2, have non-negative eigenvalues.
Roger Stafford
Where, exactly, are you getting these definitions from? Can you post
some web links? The Hermitian restriction does not agree with my
understanding at all. For a matrix M to be positive semi-definite, it
simply has to satisfy this (which I am sure you already know but I
repeat for others):
x' * M * x >= 0 for all non-zero vectors x
where x' is the complex conjugate transpose operator.
And testing the sign of all of the eigenvalues of M is a necessary and
sufficient test for this. I am not sure what the M + M' calculation in
your post (from other links) has to do with this. For example, see
this wiki link which agrees with my understanding:
http://en.wikipedia.org/wiki/Positive-definite_matrix
Here is an example of a random matrix I generated in MATLAB that is
not Hermitian but is positive semi-definite:
0.95012928514718 0.48598246870930 0.45646766516834
0.23113851357429 0.89129896614890 0.01850364324822
0.60684258354179 0.76209683302739 0.82140716429525
A Hermitian matrix (i.e., where isequal(M,M') is true ) *will* be
positive semi-definite (an easy thing to prove), but it is not a
necessary condition for positive semi-definiteness. Perhaps this is
where the confusion is?
James Tursa
In particular you will note that if you were to require that your expression
x'*M*x above be real and non-negative for all complex vectors x, then M
must necessarily be Hermitian. If you only require that the real part of x'*M*x
be non-negative for all complex x, then that would allow M to be non-
Hermitian.
Here are the web sites and quotations which I refer you to:
-----------------------------------------------------
http://en.wikipedia.org/wiki/Positive-definite_matrix
"In linear algebra, a positive-definite matrix is a Hermitian matrix which in
many ways is analogous to a positive real number."
-----------------------------------------------------
http://mathworld.wolfram.com/PositiveSemidefiniteMatrix.html
"A positive semidefinite matrix is a Hermitian matrix all of whose eigenvalues
are nonnegative."
-----------------------------------------------------
http://www.halfvalue.com/wiki.jsp?topic=Positive-definite_matrix
"Non-Hermitian matrices
A real matrix M may have the property that xTMx > 0 for all nonzero real
vectors x without being symmetric. The matrix
[1 1
0 1]
provides an example. In general, we have xTMx > 0 for all real nonzero
vectors x if and only if the symmetric part, (M + MT) / 2, is positive definite.
The situation for complex matrices may be different, depending on how one
generalizes the inequality z*Mz > 0. If z*Mz is real for all complex vectors z,
then the matrix M is necessarily Hermitian. So, if we require that z*Mz be real
and positive, then M is automatically Hermitian. On the other hand, we have
that Re(z*Mz) > 0 for all complex nonzero vectors z if and only if the
Hermitian part, (M + M*) / 2, is positive definite.
In summary, the distinguishing feature between the real and complex case is
that, a bounded positive operator on a complex Hilbert space is necessarily
Hermitian, or self adjoint. The general claim can be argued using the
polarization identity. That is no longer true in the real case.
There is no agreement in the literature on the proper definition of positive-
definite for non-Hermitian matrices."
-----------------------------------------------------
Roger Stafford
*groan* ... I meant to write that a Hermitian matrix has real
eigenvalues, not that it is necessarily positive semi-definite.
let's
a =
0.8147 0.9134 0.2785
0.9058 0.6324 0.5469
0.1270 0.0975 0.9575
then;
>> ata=a'*a;
>> eig(ata)
ans =
0.0329
0.7038
3.3007
>> ata2=(a'+a);
>> eig(ata2)
ans =
-0.4007
1.6130
3.5969
So, that means (a'+a)/2 may not be a positive-define matrix.
Regard
Lanyi