File: transforms_svd.html

package info (click to toggle)
freemat 4.0-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 174,756 kB
  • ctags: 67,023
  • sloc: cpp: 351,059; ansic: 255,892; sh: 40,590; makefile: 4,387; perl: 4,058; asm: 3,313; pascal: 2,718; fortran: 1,722; ada: 1,681; ml: 1,360; cs: 879; csh: 795; python: 430; sed: 162; lisp: 160; awk: 5
file content (101 lines) | stat: -rw-r--r-- 2,540 bytes parent folder | download | duplicates (2)
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>
--&gt; A = float(randn(2,3))

A = 
   -0.9542    1.2478   -0.2295 
    0.3075    1.0686   -0.4849 

--&gt; [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 

--&gt; U*S*V'

ans = 
   -0.9542    1.2478   -0.2295 
    0.3075    1.0686   -0.4849 

--&gt; svd(A)

ans = 
    1.8058 
    0.8549 
</PRE>
<P>
</BODY>
</HTML>