mikexcohen / LinAlg4DataScience

Code that accompanies the book "Linear Algebra for Data Science"
284 stars 144 forks source link

Wrong formula #5

Open LysanetsAndriy opened 1 year ago

LysanetsAndriy commented 1 year ago

Page 232 shows the incorrect formula: $C = A B^{-1}$. From the previous formula $Av = λBv$ we can derive $C = B^{-1}A$, instead of $C = A B^{-1}$ this way: $Av = λBv$, $B^{-1}Av = B^{-1}λBv$, $(B^{-1}A) v = λ (B^{-1}B) v$, $Cv = λIv = λv$ So $C = B^{-1}A$

Also, I tested this in the notebook for Chapter 13 by adding some code in the section "Generalized eigendecomposition": ... C1 = np.linalg.inv(B) @ A C2 = A @ np.linalg.inv(B) print(np.round(C1 @ evecs - evals * evecs,6)) print(np.round(C2 @ evecs - evals * evecs,6)) Output:

[[-0. -0. -0.  0.]
 [-0.  0.  0.  0.]
 [ 0.  0.  0.  0.]
 [-0. -0.  0.  0.]]
[[ 0.595699  0.643987  0.379455  0.922702]
 [ 0.704559  0.913965  0.558771 -4.758518]
 [-0.578492 -0.805236 -0.496454  5.629797]
 [ 1.53264   1.720669  1.008171 -0.076947]]
mikexcohen commented 1 year ago

Ah, great catch, Andriy. Thanks for reporting that typo. Indeed, the GED is inv(B)@A, not A@inv(B).