How does Matlabs svd() function calculate the value of V?

조회 수: 5 (최근 30일)
Caleb
Caleb 2025년 6월 10일
편집: David Goodmanson 2025년 6월 18일
I have been attempting to recreate the singular value decomposition in Matlab without the use of the svd() function. I have been able to get the values of S and U, but I have had issues recreating the results of V. I have been using the definition of V= orthogonal basis of X' * X, where X has dimensions of M * N, represented in code as
V=orth(transpose(X) * X);
However, the output of this is a N * M matrix, while the expected dimensions (and the dimensions of V in the svd function) is M * M. I seem to be missing the last colum of the matrix consistantly. Am I misunderstanding the theory behind svd, or is there an issue with the orth() command?
  댓글 수: 12
Paul
Paul 2025년 6월 15일
Hi David,
According to the doc page at eig - Eigenvalues and eigenvectors - MATLAB, "If A is real symmetric, Hermitian, or skew-Hermitian, then the right eigenvectors V [returned by eig] are orthonormal."
Does that assuage concerns about v?
I added the part in brackets because, it seems to me, that the eigenvectors associated with repeated eigenvalues of a symmetric matrix don't have to be orthonormal, though it looks like eig does enforce that for the single input case, e.g.,
Z = zeros(2);
[V,D] = eig(Z)
V = 2×2
1 0 0 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
D = 2×2
0 0 0 0
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
[V,D] = eig(eye(2))
V = 2×2
1 0 0 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
D = 2×2
1 0 0 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
I am curious as to how eig() works for symmetric matrices. Does it use issymmetric (or equivalent) on the input and take different paths depending on the result? Also, is M = A'*A guaranteed to always be symmetric in floating point (I thought that Matlab will magically ensure that M is symmetric, but I can't find anything on point in the doc).
The two-input form of eig is more interesting (I readily confess to not being that familiar with the generalized eigenvalue problem)
[V,D] = eig(Z,Z,'chol')
V = 2×2
1 0 0 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
D = 2×2
NaN 0 0 NaN
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
[V,D] = eig(Z,Z,'qz')
V = 2×2
1 0 0 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
D = 2×2
NaN 0 0 NaN
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
I don't know what to make of the D-matrix, insofar as any finite D and any finite, non-zero V will satisfy Z*V = Z*V*D
David Goodmanson
David Goodmanson 2025년 6월 17일
편집: David Goodmanson 2025년 6월 18일
Hi Paul, as I said I didn't doubt that Matlab eig (with one input) produces an orthonormal matrix for V, whether the eigenvalues are repeated or not. I wasn't positive if in the repeated case, the resulting u from
u = A*v/s
would always be correct. But now I have verified it both by proof and example. So the initial caveat I had is unnecessary.
In what you posted above, is Z still hanging around as zeros(2) from the first line? Then it will be hard to construct anything out of eig(Z,Z).

댓글을 달려면 로그인하십시오.

답변 (2개)

John D'Errico
John D'Errico 2025년 6월 10일
편집: John D'Errico 2025년 6월 10일
UM, You seriously do not want to use X'*X to compute anything about the SVD. Yes, mathematically, it is the same. But this is not the case computationally!!!!!!
How does MATLAB compute the singular vectors? It probably calls code from LAPACK, as I recall. When I wrote my own SVD code a million years ago, based on the old LINPACK algorithms, the idea was to bidiagonalize the matrix using Householder transformations. Then I recall I needed to do Givens rotations to finish things off, killing off the off-diagonal elements one at a time. (Its been a long time since I needed an SVD, so that is just my fading memory.) You can find the basic algorithm I used back then in the original LINPACK manual.
The point is, at no time do you EVER want to form X'*X. The problem is, once you do that, you destroy any information available down in the lower significant bits of your array. And this is why, when you tried to do it, those small singular values (and their associated singular vectors) are complete crap. Worthless.
  댓글 수: 1
James Tursa
James Tursa 2025년 6월 14일
편집: James Tursa 2025년 6월 14일
E.g., some LAPACK documentation for SVD computation routines can be found on netlib:

댓글을 달려면 로그인하십시오.


Christine Tobler
Christine Tobler 2025년 6월 10일
편집: Christine Tobler 2025년 6월 10일
Hi Caleb,
Happy to discuss the svd with you!
That being said, as others here have mentioned, svd is a building block and not easy to implement. Things like orth, rank, null, pinv all are built on top of the SVD, and so wouldn't be an independent way of computing the SVD.
There are some ways to write up the SVD through symmetricEIG, but then EIG is similarly a building block and hard to implement - so it's a bit like going in circles.
What is your final goal? Would you like to understand how the SVD is computed? Or are you looking at a specific problem where you are currently using the SVD?
  댓글 수: 1
Caleb
Caleb 2025년 6월 11일
I was attempting to ensure that I understood the singular value theory and what each component was. However, as I now see from your comment and others, this might be a bigger task than I initially assumed.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Linear Algebra에 대해 자세히 알아보기

태그

제품


릴리스

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by