updating week 35

This commit is contained in:
Morten Hjorth-Jensen
2021-09-02 09:41:54 +02:00
parent ed2dca03a8
commit ddda79f449
6 changed files with 30 additions and 30 deletions
+6 -6
View File
@@ -1719,7 +1719,7 @@ As an example, the above defective matrix can be decomposed as
<p>&nbsp;<br>
$$
\boldsymbol{X} = \frac{1}{\sqrt{2}}\begin{bmatrix} 1& 1 \\ 1& -1\\ \end{bmatrix} \begin{bmatrix} 4& 0 \\ 0& 0\\ \end{bmatrix} \frac{1}{\sqrt{2}}\begin{bmatrix} 1& -1 \\ 1& 1\\ \end{bmatrix}=\boldsymbol{U}\boldsymbol{\Sigma}\boldsymbol{V}^T,
\boldsymbol{X} = \frac{1}{\sqrt{2}}\begin{bmatrix} 1& 1 \\ 1& -1\\ \end{bmatrix} \begin{bmatrix} 2& 0 \\ 0& 0\\ \end{bmatrix} \frac{1}{\sqrt{2}}\begin{bmatrix} 1& -1 \\ 1& 1\\ \end{bmatrix}=\boldsymbol{U}\boldsymbol{\Sigma}\boldsymbol{V}^T,
$$
<p>&nbsp;<br>
@@ -1788,7 +1788,7 @@ In general the economy-size SVD leads to less FLOPS and still conserving the des
<span style="color: #CD5555"> SVD is numerically more stable than the inversion algorithms provided by</span>
<span style="color: #CD5555"> numpy and scipy.linalg at the cost of being slower.</span>
<span style="color: #CD5555"> &#39;&#39;&#39;</span>
U, S, VT = np.linalg.svd(A)
U, S, VT = np.linalg.svd(A,full_matrices=<span style="color: #8B008B; font-weight: bold">True</span>)
<span style="color: #658b00">print</span>(<span style="color: #CD5555">&#39;test U&#39;</span>)
<span style="color: #658b00">print</span>( (np.transpose(U) @ U - U <span style="color: #707a7c">@np</span>.transpose(U)))
<span style="color: #658b00">print</span>(<span style="color: #CD5555">&#39;test VT&#39;</span>)
@@ -1804,12 +1804,12 @@ In general the economy-size SVD leads to less FLOPS and still conserving the des
X = np.array([ [<span style="color: #B452CD">1.0</span>,-<span style="color: #B452CD">1.0</span>], [<span style="color: #B452CD">1.0</span>,-<span style="color: #B452CD">1.0</span>]])
<span style="color: #228B22">#X = np.array([[1, 2], [3, 4], [5, 6]])</span>
<span style="color: #658b00">print</span>(X)
A = np.transpose(X) @ X
<span style="color: #658b00">print</span>(A)
C = SVDinv(A)
C = SVDinv(X)
<span style="color: #228B22"># Print the difference between the original matrix and the SVD one</span>
<span style="color: #658b00">print</span>(C-A)
<span style="color: #658b00">print</span>(C-X)
</pre></div>
<p>
The matrix \( \boldsymbol{X} \) has columns that are linearly dependent. The first
+6 -6
View File
@@ -1794,7 +1794,7 @@ $$
As an example, the above defective matrix can be decomposed as
$$
\boldsymbol{X} = \frac{1}{\sqrt{2}}\begin{bmatrix} 1& 1 \\ 1& -1\\ \end{bmatrix} \begin{bmatrix} 4& 0 \\ 0& 0\\ \end{bmatrix} \frac{1}{\sqrt{2}}\begin{bmatrix} 1& -1 \\ 1& 1\\ \end{bmatrix}=\boldsymbol{U}\boldsymbol{\Sigma}\boldsymbol{V}^T,
\boldsymbol{X} = \frac{1}{\sqrt{2}}\begin{bmatrix} 1& 1 \\ 1& -1\\ \end{bmatrix} \begin{bmatrix} 2& 0 \\ 0& 0\\ \end{bmatrix} \frac{1}{\sqrt{2}}\begin{bmatrix} 1& -1 \\ 1& 1\\ \end{bmatrix}=\boldsymbol{U}\boldsymbol{\Sigma}\boldsymbol{V}^T,
$$
<p>
@@ -1862,7 +1862,7 @@ In general the economy-size SVD leads to less FLOPS and still conserving the des
<span style="color: #CD5555"> SVD is numerically more stable than the inversion algorithms provided by</span>
<span style="color: #CD5555"> numpy and scipy.linalg at the cost of being slower.</span>
<span style="color: #CD5555"> &#39;&#39;&#39;</span>
U, S, VT = np.linalg.svd(A)
U, S, VT = np.linalg.svd(A,full_matrices=<span style="color: #8B008B; font-weight: bold">True</span>)
<span style="color: #658b00">print</span>(<span style="color: #CD5555">&#39;test U&#39;</span>)
<span style="color: #658b00">print</span>( (np.transpose(U) @ U - U <span style="color: #707a7c">@np</span>.transpose(U)))
<span style="color: #658b00">print</span>(<span style="color: #CD5555">&#39;test VT&#39;</span>)
@@ -1878,12 +1878,12 @@ In general the economy-size SVD leads to less FLOPS and still conserving the des
X = np.array([ [<span style="color: #B452CD">1.0</span>,-<span style="color: #B452CD">1.0</span>], [<span style="color: #B452CD">1.0</span>,-<span style="color: #B452CD">1.0</span>]])
<span style="color: #228B22">#X = np.array([[1, 2], [3, 4], [5, 6]])</span>
<span style="color: #658b00">print</span>(X)
A = np.transpose(X) @ X
<span style="color: #658b00">print</span>(A)
C = SVDinv(A)
C = SVDinv(X)
<span style="color: #228B22"># Print the difference between the original matrix and the SVD one</span>
<span style="color: #658b00">print</span>(C-A)
<span style="color: #658b00">print</span>(C-X)
</pre></div>
<p>
The matrix \( \boldsymbol{X} \) has columns that are linearly dependent. The first
+6 -6
View File
@@ -1799,7 +1799,7 @@ $$
As an example, the above defective matrix can be decomposed as
$$
\boldsymbol{X} = \frac{1}{\sqrt{2}}\begin{bmatrix} 1& 1 \\ 1& -1\\ \end{bmatrix} \begin{bmatrix} 4& 0 \\ 0& 0\\ \end{bmatrix} \frac{1}{\sqrt{2}}\begin{bmatrix} 1& -1 \\ 1& 1\\ \end{bmatrix}=\boldsymbol{U}\boldsymbol{\Sigma}\boldsymbol{V}^T,
\boldsymbol{X} = \frac{1}{\sqrt{2}}\begin{bmatrix} 1& 1 \\ 1& -1\\ \end{bmatrix} \begin{bmatrix} 2& 0 \\ 0& 0\\ \end{bmatrix} \frac{1}{\sqrt{2}}\begin{bmatrix} 1& -1 \\ 1& 1\\ \end{bmatrix}=\boldsymbol{U}\boldsymbol{\Sigma}\boldsymbol{V}^T,
$$
<p>
@@ -1867,7 +1867,7 @@ In general the economy-size SVD leads to less FLOPS and still conserving the des
<span style="color: #BA2121; font-style: italic"> SVD is numerically more stable than the inversion algorithms provided by</span>
<span style="color: #BA2121; font-style: italic"> numpy and scipy.linalg at the cost of being slower.</span>
<span style="color: #BA2121; font-style: italic"> &#39;&#39;&#39;</span>
U, S, VT <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linalg<span style="color: #666666">.</span>svd(A)
U, S, VT <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linalg<span style="color: #666666">.</span>svd(A,full_matrices<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">True</span>)
<span style="color: #008000">print</span>(<span style="color: #BA2121">&#39;test U&#39;</span>)
<span style="color: #008000">print</span>( (np<span style="color: #666666">.</span>transpose(U) <span style="color: #666666">@</span> U <span style="color: #666666">-</span> U <span style="color: #AA22FF">@np</span><span style="color: #666666">.</span>transpose(U)))
<span style="color: #008000">print</span>(<span style="color: #BA2121">&#39;test VT&#39;</span>)
@@ -1883,12 +1883,12 @@ In general the economy-size SVD leads to less FLOPS and still conserving the des
X <span style="color: #666666">=</span> np<span style="color: #666666">.</span>array([ [<span style="color: #666666">1.0</span>,<span style="color: #666666">-1.0</span>], [<span style="color: #666666">1.0</span>,<span style="color: #666666">-1.0</span>]])
<span style="color: #408080; font-style: italic">#X = np.array([[1, 2], [3, 4], [5, 6]])</span>
<span style="color: #008000">print</span>(X)
A <span style="color: #666666">=</span> np<span style="color: #666666">.</span>transpose(X) <span style="color: #666666">@</span> X
<span style="color: #008000">print</span>(A)
C <span style="color: #666666">=</span> SVDinv(A)
C <span style="color: #666666">=</span> SVDinv(X)
<span style="color: #408080; font-style: italic"># Print the difference between the original matrix and the SVD one</span>
<span style="color: #008000">print</span>(C<span style="color: #666666">-</span>A)
<span style="color: #008000">print</span>(C<span style="color: #666666">-</span>X)
</pre></div>
<p>
The matrix \( \boldsymbol{X} \) has columns that are linearly dependent. The first
Binary file not shown.
+6 -6
View File
@@ -2118,7 +2118,7 @@
"metadata": {},
"source": [
"$$\n",
"\\boldsymbol{X} = \\frac{1}{\\sqrt{2}}\\begin{bmatrix} 1& 1 \\\\ 1& -1\\\\ \\end{bmatrix} \\begin{bmatrix} 4& 0 \\\\ 0& 0\\\\ \\end{bmatrix} \\frac{1}{\\sqrt{2}}\\begin{bmatrix} 1& -1 \\\\ 1& 1\\\\ \\end{bmatrix}=\\boldsymbol{U}\\boldsymbol{\\Sigma}\\boldsymbol{V}^T,\n",
"\\boldsymbol{X} = \\frac{1}{\\sqrt{2}}\\begin{bmatrix} 1& 1 \\\\ 1& -1\\\\ \\end{bmatrix} \\begin{bmatrix} 2& 0 \\\\ 0& 0\\\\ \\end{bmatrix} \\frac{1}{\\sqrt{2}}\\begin{bmatrix} 1& -1 \\\\ 1& 1\\\\ \\end{bmatrix}=\\boldsymbol{U}\\boldsymbol{\\Sigma}\\boldsymbol{V}^T,\n",
"$$"
]
},
@@ -2185,7 +2185,7 @@
" SVD is numerically more stable than the inversion algorithms provided by\n",
" numpy and scipy.linalg at the cost of being slower.\n",
" '''\n",
" U, S, VT = np.linalg.svd(A)\n",
" U, S, VT = np.linalg.svd(A,full_matrices=True)\n",
" print('test U')\n",
" print( (np.transpose(U) @ U - U @np.transpose(U)))\n",
" print('test VT')\n",
@@ -2201,12 +2201,12 @@
"\n",
"\n",
"X = np.array([ [1.0,-1.0], [1.0,-1.0]])\n",
"#X = np.array([[1, 2], [3, 4], [5, 6]])\n",
"\n",
"print(X)\n",
"A = np.transpose(X) @ X\n",
"print(A)\n",
"C = SVDinv(A)\n",
"C = SVDinv(X)\n",
"# Print the difference between the original matrix and the SVD one\n",
"print(C-A)"
"print(C-X)"
]
},
{
+6 -6
View File
@@ -1322,7 +1322,7 @@ As an example, the above defective matrix can be decomposed as
!bt
\[
\bm{X} = \frac{1}{\sqrt{2}}\begin{bmatrix} 1& 1 \\ 1& -1\\ \end{bmatrix} \begin{bmatrix} 4& 0 \\ 0& 0\\ \end{bmatrix} \frac{1}{\sqrt{2}}\begin{bmatrix} 1& -1 \\ 1& 1\\ \end{bmatrix}=\bm{U}\bm{\Sigma}\bm{V}^T,
\bm{X} = \frac{1}{\sqrt{2}}\begin{bmatrix} 1& 1 \\ 1& -1\\ \end{bmatrix} \begin{bmatrix} 2& 0 \\ 0& 0\\ \end{bmatrix} \frac{1}{\sqrt{2}}\begin{bmatrix} 1& -1 \\ 1& 1\\ \end{bmatrix}=\bm{U}\bm{\Sigma}\bm{V}^T,
\]
!et
@@ -1378,7 +1378,7 @@ def SVDinv(A):
SVD is numerically more stable than the inversion algorithms provided by
numpy and scipy.linalg at the cost of being slower.
'''
U, S, VT = np.linalg.svd(A)
U, S, VT = np.linalg.svd(A,full_matrices=True)
print('test U')
print( (np.transpose(U) @ U - U @np.transpose(U)))
print('test VT')
@@ -1394,12 +1394,12 @@ def SVDinv(A):
X = np.array([ [1.0,-1.0], [1.0,-1.0]])
#X = np.array([[1, 2], [3, 4], [5, 6]])
print(X)
A = np.transpose(X) @ X
print(A)
C = SVDinv(A)
C = SVDinv(X)
# Print the difference between the original matrix and the SVD one
print(C-A)
print(C-X)
!ec
The matrix $\bm{X}$ has columns that are linearly dependent. The first