Skip to content

Commit 836062e

Browse files
Tom's Dec 24 edits of svd lecture
1 parent 5dd4646 commit 836062e

File tree

1 file changed

+54
-9
lines changed

1 file changed

+54
-9
lines changed

lectures/svd_intro.md

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ vectors $z$ that can be written as linear combinations of rows of $X$. Its dime
133133
* The **left null space** of $X$, denoted ${\mathcal N}(X^T)$, consist of all vectors $z$ such that
134134
$X^T z =0$. Its dimension is $n-p$.
135135

136-
A full SVD of a matrix $X$ contains orthogonal bases for all four subspaces.
136+
The $U$ and $V$ factors for a full SVD of a matrix $X$ contain orthogonal bases for all four subspaces.
137137

138-
And the subspaces are connected in interesting ways, consisting of two pairs of orthogonal subspaces
138+
The subspaces are connected in interesting ways, consisting of two pairs of orthogonal subspaces
139139
that we'll describe here.
140140

141141
Let $u_i, i = 1, \ldots, m$ be the $m$ column vectors of $U$ and let
@@ -165,29 +165,31 @@ These matrices are related to the four fundamental subspaces of $X$ in the follo
165165
$$
166166
\begin{aligned}
167167
{\mathcal C}(X) & = {\mathcal C}(U_L) \cr
168-
{\mathcal N}(X) & = {\mathcal C} (V_R) \cr
168+
{\mathcal N}(X^T) & = {\mathcal C}(U_R) \cr
169169
{\mathcal R}(X) & \equiv {\mathcal C}(X^T) = {\mathcal C} (V_L) \cr
170-
{\mathcal N}(X^T) & = {\mathcal C}(U_R)
170+
{\mathcal N}(X) & = {\mathcal C} (V_R) \cr
171+
171172
\end{aligned}
172173
$$ (eq:fourspaceSVD)
173174
174175
175176
Here ${\mathcal C}$ denotes a column space, ${\mathcal N}$ denotes a null space, and ${\mathcal R}$ denotes a row space.
176177
177-
Collection {eq}`eq:fourspaceSVD` asserts that
178+
Since $U$ and $V$ are both orthonormal matrices, collection {eq}`eq:fourspaceSVD` asserts that
178179
179180
* $U_L$ is an orthonormal basis for the column space of $X$
181+
* $U_R$ is an orthonormal basis for the null space of $X^T$
182+
* $V_L$ is an orthonormal basis for the row space of $X$
180183
* $V_R$ is an orthonormal basis for the null space of $X$
181-
* $V_L$ is an orthonormal basis for the range space of $X$
182-
* $U_R$ is an orthonormal basis for the column space of $X^T$
184+
183185
184186
The four claims in {eq}`eq:fourspaceSVD` can be verified by performing the multiplications called for by the right side of {eq}`eq:fullSVDpartition` and interpreting them.
185187
186188
Although we won't go through the details of that verification here, we will note that the claims in {eq}`eq:fourspaceSVD` and the fact that $U$ and $V$ are both unitary (i.e, orthonormal) matrices immediately implies
187189
that
188190
189-
* the column space of $X$ is orthogonal to the column space of of $X^T$
190-
* the null space of $X$ is orthogonal to the range space of $X$
191+
* the column space of $X$ is orthogonal to the null space of of $X^T$
192+
* the null space of $X$ is orthogonal to the row space of $X$
191193
192194
Sometimes these properties are described with the following two pairs of orthogonal complement subspaces:
193195
@@ -196,6 +198,49 @@ Sometimes these properties are described with the following two pairs of orthogo
196198
197199
198200
201+
Let's do an example.
202+
203+
```{code-cell} ipython3
204+
np.set_printoptions(precision=2)
205+
206+
# Define the matrix
207+
A = np.array([[1, 2, 3, 4, 5],
208+
[2, 3, 4, 5, 6],
209+
[3, 4, 5, 6, 7],
210+
[4, 5, 6, 7, 8],
211+
[5, 6, 7, 8, 9]])
212+
213+
# Compute the SVD of the matrix
214+
U, S, V = np.linalg.svd(A,full_matrices=True)
215+
216+
# Compute the rank of the matrix
217+
rank = np.linalg.matrix_rank(A)
218+
219+
# Print the rank of the matrix
220+
print("Rank of matrix:\n", rank)
221+
print("S: \n", S)
222+
223+
# Compute the four fundamental subspaces
224+
row_space = U[:, :rank]
225+
col_space = V[:, :rank]
226+
null_space = V[:, rank:]
227+
left_null_space = U[:, rank:]
228+
229+
230+
print("U:\n", U)
231+
print("Column space:\n", col_space)
232+
print("Left null space:\n", left_null_space)
233+
print("V.T:\n", V.T)
234+
print("Row space:\n", row_space.T)
235+
print("Right null space:\n", null_space.T)
236+
```
237+
238+
239+
240+
241+
242+
243+
199244
## Properties of Full and Reduced SVD's
200245
201246
Up to now we have described properties of a **full** SVD in which shapes of $U$, $\Sigma$, and $V$ are $\left(m, m\right)$, $\left(m, n\right)$, $\left(n, n\right)$, respectively.

0 commit comments

Comments
 (0)