1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE>SVD Singular Value Decomposition of a Matrix
</TITLE>
</HEAD>
<BODY>
<H2>SVD Singular Value Decomposition of a Matrix
</H2>
<P>
Section: <A HREF=sec_transforms.html> Transforms/Decompositions </A>
<H3>Usage</H3>
Computes the singular value decomposition (SVD) of a matrix. The
<code>svd</code> function has three forms. The first returns only the singular
values of the matrix:
<PRE>
s = svd(A)
</PRE>
<P>
The second form returns both the singular values in a diagonal
matrix <code>S</code>, as well as the left and right eigenvectors.
<PRE>
[U,S,V] = svd(A)
</PRE>
<P>
The third form returns a more compact decomposition, with the
left and right singular vectors corresponding to zero singular
values being eliminated. The syntax is
<PRE>
[U,S,V] = svd(A,0)
</PRE>
<P>
<H3>Function Internals</H3>
Recall that <code>sigma_i</code> is a singular value of an <code>M x N</code>
matrix <code>A</code> if there exists two vectors <code>u_i, v_i</code> where <code>u_i</code> is
of length <code>M</code>, and <code>v_i</code> is of length <code>u_i</code> and
<P>
<DIV ALIGN="CENTER">
<IMG SRC="svd_eqn1.png">
</DIV>
<P>
and generally
<P>
<DIV ALIGN="CENTER">
<IMG SRC="svd_eqn2.png">
</DIV>
<P>
where <code>K</code> is the rank of <code>A</code>. In matrix form, the left singular
vectors <code>u_i</code> are stored in the matrix <code>U</code> as
<P>
<DIV ALIGN="CENTER">
<IMG SRC="svd_eqn3.png">
</DIV>
<P>
The matrix <code>S</code> is then of size <code>M x N</code> with the singular
values along the diagonal. The SVD is computed using the
<code>LAPACK</code> class of functions <code>GESVD</code> (Note that this has
changed. Previous versions of FreeMat used <code>GESDD</code>, which
yields a valid, but slightly different choice of the decomposition.
Starting in version 4, it was changed to <code>GESVD</code> to improve
compatibility.
<H3>Examples</H3>
Here is an example of a partial and complete singular value
decomposition.
<PRE>
--> A = float(randn(2,3))
A =
-0.9542 1.2478 -0.2295
0.3075 1.0686 -0.4849
--> [U,S,V] = svd(A)
U =
-0.8410 -0.5411
-0.5411 0.8410
S =
1.8058 0 0
0 0.8549 0
V =
0.3522 0.9064 0.2331
-0.9013 0.2614 0.3454
0.2521 -0.3317 0.9091
--> U*S*V'
ans =
-0.9542 1.2478 -0.2295
0.3075 1.0686 -0.4849
--> svd(A)
ans =
1.8058
0.8549
</PRE>
<P>
</BODY>
</HTML>
|