-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmit18065.jl
1349 lines (1101 loc) · 39 KB
/
mit18065.jl
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
### A Pluto.jl notebook ###
# v0.17.3
using Markdown
using InteractiveUtils
# ╔═╡ 23e4c789-2cc8-4565-9042-02168b16beac
begin
using PlutoUI
using LinearAlgebra
using Symbolics
function pp(xs...)
for x ∈ xs
print(isa(x, AbstractArray) ? repr("text/plain", x) : x)
end
print("\n\n")
end
term = PlutoUI.with_terminal
md"""
Assignments of [MIT 18.065 - Matrix Methods in Data Analysis, Signal Processing, and Machine Learning](https://ocw.mit.edu/courses/mathematics/18-065-matrix-methods-in-data-analysis-signal-processing-and-machine-learning-spring-2018/assignments/)
Source: [https://github.com/maxwindiff/maths](https://github.com/maxwindiff/maths)
"""
end
# ╔═╡ 3d9413a9-32aa-439e-8a5d-aa60ab15a651
md"""
### 1. The Column Space of ``A`` Contains All Vectors ``Ax``
"""
# ╔═╡ f5334940-2e47-4301-9508-ecfc7108f334
md"""
**(1.1)** Give an example where a combination of three nonzero vectors in ``\mathbf{R}^4`` is the zero vector. Then write your example in the form ``A\mathbf{x} = \mathbf{0}``. What are the shapes of ``A`` and ``\mathbf{x}`` and ``\mathbf{0}``?
"""
# ╔═╡ 246fff04-6614-11ec-22e1-d995b65a10a2
let
A = [1 0 1
0 1 1
0 0 0
0 0 0]
x = [1
1
-1]
z = A * x
@assert size(A) == (4,3)
@assert size(x) == (3,)
@assert size(z) == (4,)
@assert z == zero(z)
end
# ╔═╡ 96c73c4a-f62c-41d6-bcc0-13944d3fd3c7
md"""
**(1.4)** Suppose ``A`` is the 3 by 3 matrix ``\mathbf{ones}(3, 3)`` of all ones. Find two independent vectors ``\mathbf{x}`` and ``\mathbf{y}`` that solve ``A\mathbf{x}=\mathbf{0}`` and ``A\mathbf{y}=\mathbf{0}``. Write that first equation ``A\mathbf{x}=\mathbf{0}`` (with numbers) as a combination of the columns of ``A``. Why don’t I ask for a third independent vector with ``A\mathbf{z} = \mathbf{0}``?
"""
# ╔═╡ 6f2f5e4e-7843-46b5-8647-3f681cfbbae0
let
A = ones(3, 3)
x = [1
-1
0]
@assert A * x == zero(A * x)
y = [1
0
-1]
@assert A * y == zero(A * y)
# A has rank 1, so dimension of null space is 3 - 1 = 2
@assert rank(A) == 1
@assert size(nullspace(A), 2) == 2
end
# ╔═╡ b344b879-d30a-420d-9e8c-410ab75c75a5
md"""
**(1.9)** Suppose the column space of an ``m`` by ``n`` matrix is all of ``\mathbf{R}^3``. What can you say about ``m``? What can you say about ``n``? What can you say about the rank ``r``?
"""
# ╔═╡ 5af2ab12-84bb-4cf5-b632-ffdfce21b8d0
md"""
**Ans:**
``m`` is 3.
``n`` is at least 3.
rank ``r`` is 3.
"""
# ╔═╡ a3511d6e-c7dc-44cc-a6b3-43e7440e32cc
md"""
**(1.18)** If ``A = CR``, what are the ``CR`` factors of the matrix
```math
\begin{equation*}
\begin{bmatrix}
0 & A \\
0 & A \\
\end{bmatrix}
\end{equation*}
```
"""
# ╔═╡ 005cde91-f411-40e8-a903-01506402c2be
term() do
C = rand(-9:9, 3, 2)
R = rand(-9:9, 2, 3)
A = C * R
A2 = kron([0 1
0 1], A)
C2 = kron([1
1], C)
R2 = kron([0 1], R)
@assert A2 == C2 * R2
pp("C2:\n", C2)
pp("R2:\n", R2)
pp("A2:\n", A2)
end
# ╔═╡ df291cf8-beb9-4481-bf71-0cc67a6dab7a
md"""
### 2. Multiplying and Factoring Matrices
"""
# ╔═╡ d9ca6fbe-dffb-4c5e-b1cf-0c80c7552088
md"""
**(2.2)** Suppose ``\mathbf{a}`` and ``\mathbf{b}`` are column vectors with components ``a_1,...,a_m`` and ``b_1,...,b_p``. Can you multiply ``\mathbf{a}`` times ``\mathbf{b}^\mathsf{T}`` (yes or no)? What is the shape of the answer ``\mathbf{ab}^\mathsf{T}``? What number is in row ``i``, column ``j`` of ``\mathbf{ab}^\mathsf{T}``? What can you say about ``\mathbf{aa}^\mathsf{T}``?
"""
# ╔═╡ d4f90e59-3b6b-4b51-b1ae-5c0f2b2aa8ea
term() do
m = 3
p = 5
a = rand(-9:9, m, 1)
b = rand(-9:9, p, 1)
abT = a * transpose(b)
pp("a:\n", a)
pp("b:\n", b)
pp("abT:\n", abT)
@assert size(abT) == (m, p)
i = rand(1:m)
j = rand(1:p)
@assert abT[i,j] == a[i] * b[j]
@assert issymmetric(a * transpose(a))
end
# ╔═╡ ced55756-9423-4f66-a755-fa7afb61c159
md"""
**(2.6)** If ``A`` has columns ``\mathbf{a}_1``, ``\mathbf{a}_2``, ``\mathbf{a}_3`` and ``B = I`` is the identity matrix, what are the rank one matrices ``\mathbf{a}_1\mathbf{b}^*_1`` and ``\mathbf{a}_2\mathbf{b}^*_2`` and ``\mathbf{a}_3\mathbf{b}^*_3``? They should add to ``AI = A``.
"""
# ╔═╡ 3d07a918-0263-4d1e-9187-b0adbbe20203
term() do
a₁ = rand(-9:9, 5, 1)
a₂ = rand(-9:9, 5, 1)
a₃ = rand(-9:9, 5, 1)
A = [a₁ a₂ a₃]
pp("A:\n", A)
B = I(3)
pp("B:\n", B)
a₁b₁T = a₁ * B[:,1]'
a₂b₂T = a₂ * B[:,2]'
a₃b₃T = a₃ * B[:,3]'
@assert a₁b₁T + a₂b₂T + a₃b₃T == A
pp("a₁:\n", a₁)
pp("b₁':\n", B[:,1]')
pp("a₁b₁':\n", a₁b₁T)
end
# ╔═╡ 56a8646f-b8b7-4241-acb6-db64333ca508
md"""
### 3. Orthonormal Columns In ``Q`` Give ``Q’Q = I``
"""
# ╔═╡ f6db2e64-dfb2-42bc-82f5-4937f78a647d
md"""
**(3.2)** Draw unit vectors ``\mathbf{u}`` and ``\mathbf{v}`` that are not orthogonal. Show that ``\mathbf{w} = \mathbf{v} − \mathbf{u}(\mathbf{u}^\mathsf{T}\mathbf{v})`` is orthogonal to ``\mathbf{u}`` (and add ``\mathbf{w}`` to your picture).
"""
# ╔═╡ 77b1153f-e462-4c75-934d-1766ee7dc89a
term() do
u = normalize([1, 0])
v = normalize([1, 2])
w = v - u * (u' * v)
println("u = ", u)
println("v = ", v)
println("u'v = ", u'*v)
println("u(u'v) = ", u*(u'*v))
println("w = ", w)
println(u'*w)
end
# ╔═╡ 13690156-b8f1-4768-b306-da7312e02f42
md"""
**(3.4)** Key property of every orthogonal matrix : ``||Q\mathbf{x}||^2 = ||\mathbf{x}||^2`` for every vector ``\mathbf{x}``. More than this, show that ``(Q\mathbf{x})^\mathsf{T}(Q\mathbf{y}) = \mathbf{x}^\mathsf{T}\mathbf{y}`` for every vector ``\mathbf{x}`` and ``\mathbf{y}``. So lengths and angles are not changed by ``Q``. Computations with ``Q`` never overflow!
"""
# ╔═╡ 1c12c1de-93a6-4b0d-ab73-65a77866ad3f
md"""
**Ans:**
```math
\begin{align}
(Q\mathbf{x})^\mathsf{T}(Q\mathbf{y}) &= \mathbf{x}^\mathsf{T}Q^\mathsf{T}Q\mathbf{y} \\
&= \mathbf{x}^\mathsf{T}\mathbf{y}
\end{align}
```
"""
# ╔═╡ 9c1e24e8-5645-40a2-8710-28652b044fe5
md"""
**(3.6)** A **permutation matrix** has the same columns as the identity matrix (in some order). Explain why this permutation matrix and every permutation matrix is orthogonal:
```math
\begin{equation*}
P =
\begin{bmatrix}
0 & 1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 \\
1 & 0 & 0 & 0 \\
\end{bmatrix}
\end{equation*}
```
has orthonormal basis so ``P^\mathsf{T}P = \_\_`` and ``P^{-1} = \_\_``.
When a matrix is symmetric or orthogonal, it will have orthogonal eigenvectors. This is the most important source of orthogonal vectors in applied mathematics.
"""
# ╔═╡ 9902ff32-2f28-4685-ac4e-a7ca492afe04
md"""
**Ans:** By definition, permutation matrices are row/column permutations of the identity matrix, so rows/columns are orthogonal to each other and have norm 1.
``P^\mathsf{T}P = I``
``P^{-1} = P^\mathsf{T}``
"""
# ╔═╡ 2a3b2f9f-da40-45c9-a72e-b2a85f488981
term() do
P = [0 1 0 0
0 0 1 0
0 0 0 1
1 0 0 0]
pp(P' * P)
end
# ╔═╡ f3f2074c-ed22-4637-93f9-1f59dc95f00d
md"""
### 4. Eigenvalues and Eigenvectors
"""
# ╔═╡ 30f3bf26-c49b-450e-8679-6f1536dd6a9e
md"""
**(4.2)** Compute the eigenvalues and eigenvectors of ``A`` and ``A^{−1}``. Check the trace!
```math
\begin{equation*}
A =
\begin{bmatrix}
0 & 2 \\
1 & 1 \\
\end{bmatrix}
\ \ \textrm{and} \ \ \
A^{-1} =
\begin{bmatrix}
-1/2 & 1 \\
1/2 & 0 \\
\end{bmatrix}
\end{equation*}
```
"""
# ╔═╡ f070e8d6-3514-4f11-9167-11842fbb61ff
term() do
A = [0 2
1 1]
println("λ(A) = ", eigvals(A))
pp(eigvecs(A))
A⁻¹ = inv(A)
println("λ(A⁻¹) = ", eigvals(A⁻¹))
pp(eigvecs(A⁻¹))
end
# ╔═╡ 0d0b23de-76f4-4e95-9f15-4e3c960b2935
md"""
This is because:
```math
\begin{equation*}
\begin{aligned}
A x &= λ x \\
A^{-1}Ax &= A^{-1} λ x \\
x &= A^{-1} λ x \\
\frac{1}{λ} x &= A^{-1} x
\end{aligned}
\end{equation*}
```
"""
# ╔═╡ bb82e3a6-8783-48a3-8807-c2836140fc97
md"""
**(4.11)** The eigenvalues of ``A`` equal the eigenvalues of ``A^\mathsf{T}``. This is because ``\textrm{det}(A − λI)`` equals ``\textrm{det}(A^\mathsf{T} − λI)``. That is true because __. Show by an example that the eigenvectors of ``A`` and ``A^\mathsf{T}`` are not the same.
"""
# ╔═╡ fb7f94d5-b746-4d40-8f8e-0127da73260c
term() do
A = [0 2
1 1]
println("λ(A) = ", eigvals(A), "\n")
pp("eigvecs(A) = ", eigvecs(A))
println("λ(A') = ", eigvals(A'), "\n")
pp("eigvecs(A') = ", eigvecs(A'))
end
# ╔═╡ e276d15d-c643-44fa-a64a-e221a1620d24
md"""
**(4.15)** Factor these two matrices into ``A = X Λ X^{-1}``:
"""
# ╔═╡ e31e2250-00ba-46c6-93c2-0f47b5562f1c
term() do
A = [1 2
0 3]
X = eigvecs(A)
Λ = Diagonal(eigvals(A))
@assert A ≈ X * Λ * inv(X)
pp("X = ", X)
pp("Λ = ", Λ)
end
# ╔═╡ 36767f04-0101-4188-847f-633c4b21079a
term() do
A = [1 1
3 3]
X = eigvecs(A)
Λ = Diagonal(eigvals(A))
@assert A ≈ X * Λ * inv(X)
pp("X = ", X)
pp("Λ = ", Λ)
end
# ╔═╡ c1813778-6a52-4ba8-abee-57377f1d50fa
md"""
### 5. Positive Definite and Semidefinite Matrices
"""
# ╔═╡ e1285f5d-121b-4be5-80ea-afcb7cc87536
md"""
**(5.3)** For which numbers ``b`` and ``c`` are these matrices positive definite?
```math
\begin{equation*}
S =
\begin{bmatrix}
1 & b \\
b & 9 \\
\end{bmatrix}
\ \ \ \ \ \
S =
\begin{bmatrix}
2 & 4 \\
4 & c \\
\end{bmatrix}
\ \ \ \ \ \
S =
\begin{bmatrix}
c & b \\
b & c \\
\end{bmatrix}
\end{equation*}
```
With the pivots in ``D`` and multiplier in ``L``, factor each ``A`` into ``LDL^\mathsf{T}``.
"""
# ╔═╡ 582db95d-38d9-4c79-b28e-95b4f9456c54
term() do
@variables b c
pp([1 0; b 1] * [1 0; 0 9-b^2] * [1 b; 0 1])
pp([1 0; 2 1] * [2 0; 0 c-8] * [1 2; 0 1])
s3 = [1 0; b/c 1] * [c 0; 0 c-b^2/c] * [1 b/c; 0 1]
pp(substitute(s3, Dict(b*c/c => b)))
end
# ╔═╡ f2312f44-b8c2-40a7-9d00-612d885fa251
md"""
**(5.14)** Find the 3 by 3 matrix ``S`` and its pivots, rank, eigenvalues, and determinant:
```math
\begin{bmatrix}
x_1 & x_2 & x_3
\end{bmatrix}
\begin{bmatrix}
S
\end{bmatrix}
\begin{bmatrix}
x_1 \\ x_2 \\ x_3
\end{bmatrix}
=
4(x_1 - x_2 + 2x_3)^2
```
"""
# ╔═╡ 86cb5caf-667a-465d-970c-047c6ee0e515
term() do
@variables x₁ x₂ x₃
pp("RHS = ", simplify(4(x₁ - x₂ + 2x₃)^2; expand=true))
v = [2, -2, 4]
S = v * v'
pp("LHS = ", simplify.([x₁ x₂ x₃] * S * [x₁, x₂, x₃]; expand=true))
@assert rank(S) == 1 # because S is the outer product of two vectors
@assert det(S) == 0 # because S has rank 1 (not full rank)
@assert v' * v ∈ eigvals(S) # because S v = (v v') v = (v'*v) v
end
# ╔═╡ 208c0647-e204-4a0b-aef9-d3b322755c95
md"""
**(5.15)** Compute the three upper left determinants of ``S`` to establish positive definiteness. Verify that their ratios give the second and third pivots.
Pivots = ratios of determinants
```math
S =
\begin{bmatrix}
2 & 2 & 0 \\
2 & 5 & 3 \\
0 & 3 & 8 \\
\end{bmatrix}
```
"""
# ╔═╡ 70b16538-c1fe-46e3-bea2-2c76ec49b912
term() do
S = [2 2 0; 2 5 3; 0 3 8]
pp("det1 = ", det(S[1:1,1:1]))
pp("det2/det1 = ", det(S[1:2,1:2]) / det(S[1:1,1:1]))
pp("det3/det2 = ", det(S[1:3,1:3]) / det(S[1:2,1:2]))
L = [1 0 0
1 1 0
0 1 1]
U = [2 2 0
0 3 3
0 0 5]
@assert L * U == S
println("pivots = ", diag(U))
end
# ╔═╡ 585396de-0dab-4860-b155-5567bd66c949
md"""
### 6. Singular Value Decomposition (SVD)
"""
# ╔═╡ 3193def8-95b0-4eda-bafa-8808374be2bd
md"""
**(6.1)** A symmetric matrix ``S = S^\mathsf{T}`` has orthonormal eigenvectors ``\mathbf{v}_1`` to ``\mathbf{v}_n``. Then any vector ``\mathbf{x}`` can be written as a combination ``\mathbf{x} = c_1\mathbf{v}_1 + ... + c_n\mathbf{v}_n``. Explain these two formulas:
```math
\mathbf{x}^\mathsf{T}\mathbf{x} = c_1^2 + ... + c_n^2
\ \ \ \ \ \ \ \ \ \ \ \ \ \
\mathbf{x}^\mathsf{T}S\mathbf{x} = λ_1 c_1^2 + ... + λ_n c_2^2
```
"""
# ╔═╡ 864dd0cd-44a9-4ef6-9471-a8dbf66cfd5d
md"""
**Ans:** Self evident.
"""
# ╔═╡ c07fde15-3c68-42cd-ba68-52fea34937f1
md"""
**(6.6)** Find the ``σ``'s and ``\mathbf{v}``'s and ``\mathbf{u}``'s in the SVD for ``A = \begin{bmatrix}3 & 4 \\ 0 & 5\end{bmatrix}``. Use equation (12).
"""
# ╔═╡ 9c4089eb-e163-4104-a867-c4320816da46
term() do
A = [3 4
0 5]
vals, V = eigen(A'A)
Σ = Diagonal(sqrt.(vals))
pp("A'A = ", A'A)
pp("V = ", V)
pp("Σ = ", Σ)
uvals, U = eigen(A*A')
if uvals ≉ vals
U = circshift(U, (0, 1)) # make sure eigenvectors are in the same order
end
pp("AA' = ", A*A')
pp("U = ", U)
@assert A ≈ U * Σ * V'
end
# ╔═╡ 466b265f-134c-4da8-b728-e35561c7f7fb
md"""
**(Book p.61)** If ``S = Q Λ Q^\mathsf{T}`` is symmetric positive definite, what is its SVD?
"""
# ╔═╡ c419a67a-7fc9-4d0d-ac9d-538e8a1b287c
term() do
Q, _ = qr(randn(3,3))
D = Diagonal([3, 2, 1])
S = Q * D * Q'
U, Σ, V = svd(S)
pp("Q = ", Q)
pp("U = ", U)
println("Σ = ", round.(Σ), "\n")
pp("V = ", V)
@assert U ≈ V
@assert all(abs.(U ./ Q) .≈ 1) # columns of U may be negated from Q
@assert Diagonal(Σ) ≈ D
end
# ╔═╡ 8bac8f84-790d-4d1e-ba47-f73b19472ff6
md"""
**(Book p.61)** If ``S = Q Λ Q^\mathsf{T}`` has a negative eigenvalue (``S\mathbf{x} = -α\mathbf{x}``), what is the singular value and what are the vectors ``\mathbf{v}`` and ``\mathbf{u}``?
"""
# ╔═╡ f53215cd-79b6-4343-9730-633a7db80c56
term() do
Q, _ = qr(randn(3,3))
D = Diagonal([3, 2, -1])
S = Q * D * Q'
U, Σ, V = svd(S)
pp("Q = ", Q)
pp("U = ", U)
pp("Σ = ", round.(Σ)) # singular values still positive
pp("V = ", V) # v₃ is negated
end
# ╔═╡ 522e7390-ff59-49c8-97ee-13ac7d85aed2
md"""
**(Book p.61)** If ``A = Q`` is an orthogonal matrix, why does every singular value equal 1?
"""
# ╔═╡ 4f503ec2-3c7b-4b1d-bf86-ab7dc27c085b
term() do
Q, _ = qr(randn(3,3))
# Q'Q is I, so eigenvalues are all 1.
pp("Q = ", Q)
pp("Q'Q = ", round.(Q'Q, digits=5))
pp("λ(Q'Q) = ", round.(eigvals(Q'Q), digits=5))
# one way to decompose: UΣ=QV where V=I, U=Q, Σ=I ==> QI=QI
Σ = Diagonal(sqrt.(eigvals(Q'Q)))
@assert Σ ≈ I
U = Q
V = I
@assert Q ≈ U * Σ * V'
end
# ╔═╡ 00000000-0000-0000-0000-000000000001
PLUTO_PROJECT_TOML_CONTENTS = """
[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
PlutoUI = "7f904dfe-b85e-4ff6-b463-dae2292396a8"
Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"
[compat]
PlutoUI = "~0.7.27"
Symbolics = "~4.2.0"
"""
# ╔═╡ 00000000-0000-0000-0000-000000000002
PLUTO_MANIFEST_TOML_CONTENTS = """
# This file is machine-generated - editing it directly is not advised
julia_version = "1.7.1"
manifest_format = "2.0"
[[deps.AbstractPlutoDingetjes]]
deps = ["Pkg"]
git-tree-sha1 = "8eaf9f1b4921132a4cff3f36a1d9ba923b14a481"
uuid = "6e696c72-6542-2067-7265-42206c756150"
version = "1.1.4"
[[deps.AbstractTrees]]
git-tree-sha1 = "03e0550477d86222521d254b741d470ba17ea0b5"
uuid = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
version = "0.3.4"
[[deps.Adapt]]
deps = ["LinearAlgebra"]
git-tree-sha1 = "9faf218ea18c51fcccaf956c8d39614c9d30fe8b"
uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
version = "3.3.2"
[[deps.ArgCheck]]
git-tree-sha1 = "dedbbb2ddb876f899585c4ec4433265e3017215a"
uuid = "dce04be8-c92d-5529-be00-80e4d2c0e197"
version = "2.1.0"
[[deps.ArgTools]]
uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f"
[[deps.ArrayInterface]]
deps = ["Compat", "IfElse", "LinearAlgebra", "Requires", "SparseArrays", "Static"]
git-tree-sha1 = "1ee88c4c76caa995a885dc2f22a5d548dfbbc0ba"
uuid = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
version = "3.2.2"
[[deps.Artifacts]]
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
[[deps.AutoHashEquals]]
git-tree-sha1 = "45bb6705d93be619b81451bb2006b7ee5d4e4453"
uuid = "15f4f7f2-30c1-5605-9d31-71845cf9641f"
version = "0.2.0"
[[deps.BangBang]]
deps = ["Compat", "ConstructionBase", "Future", "InitialValues", "LinearAlgebra", "Requires", "Setfield", "Tables", "ZygoteRules"]
git-tree-sha1 = "95831c49cf801756a922e50641361e3b4476a782"
uuid = "198e06fe-97b7-11e9-32a5-e1d131e6ad66"
version = "0.3.33"
[[deps.Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
[[deps.Baselet]]
git-tree-sha1 = "aebf55e6d7795e02ca500a689d326ac979aaf89e"
uuid = "9718e550-a3fa-408a-8086-8db961cd8217"
version = "0.1.1"
[[deps.Bijections]]
git-tree-sha1 = "705e7822597b432ebe152baa844b49f8026df090"
uuid = "e2ed5e7c-b2de-5872-ae92-c73ca462fb04"
version = "0.1.3"
[[deps.ChainRulesCore]]
deps = ["Compat", "LinearAlgebra", "SparseArrays"]
git-tree-sha1 = "d711603452231bad418bd5e0c91f1abd650cba71"
uuid = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
version = "1.11.3"
[[deps.ChangesOfVariables]]
deps = ["ChainRulesCore", "LinearAlgebra", "Test"]
git-tree-sha1 = "bf98fa45a0a4cee295de98d4c1462be26345b9a1"
uuid = "9e997f8a-9a97-42d5-a9f1-ce6bfc15e2c0"
version = "0.1.2"
[[deps.ColorTypes]]
deps = ["FixedPointNumbers", "Random"]
git-tree-sha1 = "024fe24d83e4a5bf5fc80501a314ce0d1aa35597"
uuid = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
version = "0.11.0"
[[deps.Combinatorics]]
git-tree-sha1 = "08c8b6831dc00bfea825826be0bc8336fc369860"
uuid = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
version = "1.0.2"
[[deps.CommonSolve]]
git-tree-sha1 = "68a0743f578349ada8bc911a5cbd5a2ef6ed6d1f"
uuid = "38540f10-b2f7-11e9-35d8-d573e4eb0ff2"
version = "0.2.0"
[[deps.Compat]]
deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "SHA", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"]
git-tree-sha1 = "44c37b4636bc54afac5c574d2d02b625349d6582"
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
version = "3.41.0"
[[deps.CompilerSupportLibraries_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae"
[[deps.CompositeTypes]]
git-tree-sha1 = "d5b014b216dc891e81fea299638e4c10c657b582"
uuid = "b152e2b5-7a66-4b01-a709-34e65c35f657"
version = "0.1.2"
[[deps.CompositionsBase]]
git-tree-sha1 = "455419f7e328a1a2493cabc6428d79e951349769"
uuid = "a33af91c-f02d-484b-be07-31d278c5ca2b"
version = "0.1.1"
[[deps.ConstructionBase]]
deps = ["LinearAlgebra"]
git-tree-sha1 = "f74e9d5388b8620b4cee35d4c5a618dd4dc547f4"
uuid = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
version = "1.3.0"
[[deps.DataAPI]]
git-tree-sha1 = "cc70b17275652eb47bc9e5f81635981f13cea5c8"
uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"
version = "1.9.0"
[[deps.DataStructures]]
deps = ["Compat", "InteractiveUtils", "OrderedCollections"]
git-tree-sha1 = "3daef5523dd2e769dad2365274f760ff5f282c7d"
uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
version = "0.18.11"
[[deps.DataValueInterfaces]]
git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6"
uuid = "e2d170a0-9d28-54be-80f0-106bbe20a464"
version = "1.0.0"
[[deps.Dates]]
deps = ["Printf"]
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
[[deps.DefineSingletons]]
git-tree-sha1 = "0fba8b706d0178b4dc7fd44a96a92382c9065c2c"
uuid = "244e2a9f-e319-4986-a169-4d1fe445cd52"
version = "0.1.2"
[[deps.DelimitedFiles]]
deps = ["Mmap"]
uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab"
[[deps.DensityInterface]]
deps = ["InverseFunctions", "Test"]
git-tree-sha1 = "80c3e8639e3353e5d2912fb3a1916b8455e2494b"
uuid = "b429d917-457f-4dbc-8f4c-0cc954292b1d"
version = "0.4.0"
[[deps.DiffRules]]
deps = ["LogExpFunctions", "NaNMath", "Random", "SpecialFunctions"]
git-tree-sha1 = "9bc5dac3c8b6706b58ad5ce24cffd9861f07c94f"
uuid = "b552c78f-8df3-52c6-915a-8e097449b14b"
version = "1.9.0"
[[deps.Distributed]]
deps = ["Random", "Serialization", "Sockets"]
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"
[[deps.Distributions]]
deps = ["ChainRulesCore", "DensityInterface", "FillArrays", "LinearAlgebra", "PDMats", "Printf", "QuadGK", "Random", "SparseArrays", "SpecialFunctions", "Statistics", "StatsBase", "StatsFuns", "Test"]
git-tree-sha1 = "6a8dc9f82e5ce28279b6e3e2cea9421154f5bd0d"
uuid = "31c24e10-a181-5473-b8eb-7969acd0382f"
version = "0.25.37"
[[deps.DocStringExtensions]]
deps = ["LibGit2"]
git-tree-sha1 = "b19534d1895d702889b219c382a6e18010797f0b"
uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
version = "0.8.6"
[[deps.DomainSets]]
deps = ["CompositeTypes", "IntervalSets", "LinearAlgebra", "StaticArrays", "Statistics"]
git-tree-sha1 = "5f5f0b750ac576bcf2ab1d7782959894b304923e"
uuid = "5b8099bc-c8ec-5219-889f-1d9e522a28bf"
version = "0.5.9"
[[deps.Downloads]]
deps = ["ArgTools", "LibCURL", "NetworkOptions"]
uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
[[deps.DynamicPolynomials]]
deps = ["DataStructures", "Future", "LinearAlgebra", "MultivariatePolynomials", "MutableArithmetics", "Pkg", "Reexport", "Test"]
git-tree-sha1 = "585de0d658506cf0fe5808026edff662bef5bf03"
uuid = "7c1d4256-1411-5781-91ec-d7bc3513ac07"
version = "0.4.1"
[[deps.EllipsisNotation]]
deps = ["ArrayInterface"]
git-tree-sha1 = "3fe985505b4b667e1ae303c9ca64d181f09d5c05"
uuid = "da5c29d0-fa7d-589e-88eb-ea29b0a81949"
version = "1.1.3"
[[deps.ExprTools]]
git-tree-sha1 = "b7e3d17636b348f005f11040025ae8c6f645fe92"
uuid = "e2ba6199-217a-4e67-a87a-7c52f15ade04"
version = "0.1.6"
[[deps.FillArrays]]
deps = ["LinearAlgebra", "Random", "SparseArrays", "Statistics"]
git-tree-sha1 = "8756f9935b7ccc9064c6eef0bff0ad643df733a3"
uuid = "1a297f60-69ca-5386-bcde-b61e274b549b"
version = "0.12.7"
[[deps.FixedPointNumbers]]
deps = ["Statistics"]
git-tree-sha1 = "335bfdceacc84c5cdf16aadc768aa5ddfc5383cc"
uuid = "53c48c17-4a7d-5ca2-90c5-79b7896eea93"
version = "0.8.4"
[[deps.Formatting]]
deps = ["Printf"]
git-tree-sha1 = "8339d61043228fdd3eb658d86c926cb282ae72a8"
uuid = "59287772-0a20-5a39-b81b-1366585eb4c0"
version = "0.4.2"
[[deps.Future]]
deps = ["Random"]
uuid = "9fa8497b-333b-5362-9e8d-4d0656e87820"
[[deps.Hyperscript]]
deps = ["Test"]
git-tree-sha1 = "8d511d5b81240fc8e6802386302675bdf47737b9"
uuid = "47d2ed2b-36de-50cf-bf87-49c2cf4b8b91"
version = "0.0.4"
[[deps.HypertextLiteral]]
git-tree-sha1 = "2b078b5a615c6c0396c77810d92ee8c6f470d238"
uuid = "ac1192a8-f4b3-4bfe-ba22-af5b92cd3ab2"
version = "0.9.3"
[[deps.IOCapture]]
deps = ["Logging", "Random"]
git-tree-sha1 = "f7be53659ab06ddc986428d3a9dcc95f6fa6705a"
uuid = "b5f81e59-6552-4d32-b1f0-c071b021bf89"
version = "0.2.2"
[[deps.IfElse]]
git-tree-sha1 = "debdd00ffef04665ccbb3e150747a77560e8fad1"
uuid = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173"
version = "0.1.1"
[[deps.InitialValues]]
git-tree-sha1 = "40c555f961d7ccf86d8ccd150b9eef379cbfa0a3"
uuid = "22cec73e-a1b8-11e9-2c92-598750a2cf9c"
version = "0.3.0"
[[deps.InteractiveUtils]]
deps = ["Markdown"]
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
[[deps.IntervalSets]]
deps = ["Dates", "EllipsisNotation", "Statistics"]
git-tree-sha1 = "3cc368af3f110a767ac786560045dceddfc16758"
uuid = "8197267c-284f-5f27-9208-e0e47529a953"
version = "0.5.3"
[[deps.InverseFunctions]]
deps = ["Test"]
git-tree-sha1 = "a7254c0acd8e62f1ac75ad24d5db43f5f19f3c65"
uuid = "3587e190-3f89-42d0-90ee-14403ec27112"
version = "0.1.2"
[[deps.IrrationalConstants]]
git-tree-sha1 = "7fd44fd4ff43fc60815f8e764c0f352b83c49151"
uuid = "92d709cd-6900-40b7-9082-c6be49f344b6"
version = "0.1.1"
[[deps.IteratorInterfaceExtensions]]
git-tree-sha1 = "a3f24677c21f5bbe9d2a714f95dcd58337fb2856"
uuid = "82899510-4779-5014-852e-03e436cf321d"
version = "1.0.0"
[[deps.JLLWrappers]]
deps = ["Preferences"]
git-tree-sha1 = "642a199af8b68253517b80bd3bfd17eb4e84df6e"
uuid = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210"
version = "1.3.0"
[[deps.JSON]]
deps = ["Dates", "Mmap", "Parsers", "Unicode"]
git-tree-sha1 = "8076680b162ada2a031f707ac7b4953e30667a37"
uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
version = "0.21.2"
[[deps.LaTeXStrings]]
git-tree-sha1 = "f2355693d6778a178ade15952b7ac47a4ff97996"
uuid = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
version = "1.3.0"
[[deps.LabelledArrays]]
deps = ["ArrayInterface", "ChainRulesCore", "LinearAlgebra", "MacroTools", "StaticArrays"]
git-tree-sha1 = "3609bbf5feba7b22fb35fe7cb207c8c8d2e2fc5b"
uuid = "2ee39098-c373-598a-b85f-a56591580800"
version = "1.6.7"
[[deps.Latexify]]
deps = ["Formatting", "InteractiveUtils", "LaTeXStrings", "MacroTools", "Markdown", "Printf", "Requires"]
git-tree-sha1 = "a8f4f279b6fa3c3c4f1adadd78a621b13a506bce"
uuid = "23fbe1c1-3f47-55db-b15f-69d7ec21a316"
version = "0.15.9"
[[deps.LibCURL]]
deps = ["LibCURL_jll", "MozillaCACerts_jll"]
uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21"
[[deps.LibCURL_jll]]
deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"]
uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0"
[[deps.LibGit2]]
deps = ["Base64", "NetworkOptions", "Printf", "SHA"]
uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"
[[deps.LibSSH2_jll]]
deps = ["Artifacts", "Libdl", "MbedTLS_jll"]
uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8"
[[deps.Libdl]]
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
[[deps.LinearAlgebra]]
deps = ["Libdl", "libblastrampoline_jll"]
uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
[[deps.LogExpFunctions]]
deps = ["ChainRulesCore", "ChangesOfVariables", "DocStringExtensions", "InverseFunctions", "IrrationalConstants", "LinearAlgebra"]
git-tree-sha1 = "e5718a00af0ab9756305a0392832c8952c7426c1"
uuid = "2ab3a3ac-af41-5b50-aa03-7779005ae688"
version = "0.3.6"
[[deps.Logging]]
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"
[[deps.MacroTools]]
deps = ["Markdown", "Random"]
git-tree-sha1 = "3d3e902b31198a27340d0bf00d6ac452866021cf"
uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
version = "0.5.9"
[[deps.Markdown]]
deps = ["Base64"]
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"
[[deps.MbedTLS_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1"
[[deps.Metatheory]]
deps = ["AutoHashEquals", "DataStructures", "Dates", "DocStringExtensions", "Parameters", "Reexport", "TermInterface", "ThreadsX", "TimerOutputs"]
git-tree-sha1 = "0886d229caaa09e9f56bcf1991470bd49758a69f"
uuid = "e9d8d322-4543-424a-9be4-0cc815abe26c"
version = "1.3.3"
[[deps.MicroCollections]]
deps = ["BangBang", "Setfield"]
git-tree-sha1 = "4f65bdbbe93475f6ff9ea6969b21532f88d359be"
uuid = "128add7d-3638-4c79-886c-908ea0c25c34"
version = "0.1.1"
[[deps.Missings]]
deps = ["DataAPI"]
git-tree-sha1 = "bf210ce90b6c9eed32d25dbcae1ebc565df2687f"
uuid = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28"
version = "1.0.2"
[[deps.Mmap]]
uuid = "a63ad114-7e13-5084-954f-fe012c677804"
[[deps.MozillaCACerts_jll]]
uuid = "14a3606d-f60d-562e-9121-12d972cd8159"
[[deps.MultivariatePolynomials]]
deps = ["DataStructures", "LinearAlgebra", "MutableArithmetics"]
git-tree-sha1 = "fa6ce8c91445e7cd54de662064090b14b1089a6d"
uuid = "102ac46a-7ee4-5c85-9060-abc95bfdeaa3"
version = "0.4.2"
[[deps.MutableArithmetics]]
deps = ["LinearAlgebra", "SparseArrays", "Test"]
git-tree-sha1 = "73deac2cbae0820f43971fad6c08f6c4f2784ff2"
uuid = "d8a4904e-b15c-11e9-3269-09a3773c0cb0"
version = "0.3.2"
[[deps.NaNMath]]
git-tree-sha1 = "f755f36b19a5116bb580de457cda0c140153f283"
uuid = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
version = "0.3.6"
[[deps.NetworkOptions]]
uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908"
[[deps.OpenBLAS_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "Libdl"]
uuid = "4536629a-c528-5b80-bd46-f80d51c5b363"
[[deps.OpenLibm_jll]]