Repetition and exercises¶

In [1]:
from IPython.lib.display import YouTubeVideo
vid = YouTubeVideo("Z3Yv1TUzZU8")
display(vid)

Let us look at the following example $$A=\begin{bmatrix} 121734 & 169217& 176624& 166662\\ 169217& 235222& 245505& 231653\\ 176624 & 245505& 256423& 242029\\ 166662& 231653& 242029& 228474\end{bmatrix}\quad b=\begin{bmatrix}634237\\ 881597\\ 920581\\ 868818\end{bmatrix}$$

In [5]:
import numpy as np
A = np.array([[121734, 169217, 176624, 166662], [169217, 235222, 245505, 231653], [176624, 245505, 256423, 242029],
              [166662, 231653, 242029, 228474]])
b = np.array([634237,881597, 920581, 868818])
x = np.linalg.solve(A,b)
print("x=",x)
x= [1.00170481 0.99897034 0.99957186 1.00025394]

IF we take that the right hand side is now b=\begin{bmatrix}634237\\ 881597\\ 920580\\ 868818\end{bmatrix}

In [6]:
c = np.array([634237,881597, 920580, 868818])
x = np.linalg.solve(A,c)
print("x=",x)
x= [16316026.0332614  -9854426.48680124 -4097527.25568108  2430330.02081108]
In [7]:
eig=np.linalg.eigvalsh(A)
print("Eigenvalues=", eig)
Eigenvalues= [1.06252778e-08 5.05278814e-01 2.21551535e+02 8.41630943e+05]

The matrix is ill conditioned!

In [32]:
print(np.linalg.cond(A,2))
79288124894603.9

More on linear systems and examples¶

In [4]:
vid = YouTubeVideo("fqYhEbMNLF4")
display(vid)
In [9]:
import numpy as np
A = np.array([[-4000, 2000, 2000], [2000, 0.78125, 0], [2000, 0, 0]])
b = np.array([400,1.3816, 1.9273])
x = np.linalg.solve(A,b)
print("x=",x)
np.matmul(A,x)
x= [ 0.00096365 -0.698496    0.9004233 ]
Out[9]:
array([400.    ,   1.3816,   1.9273])
In [11]:
D = np.array([[0.0005, 0, 0], [0, 1, 0], [0, 0, 1]])
In [12]:
B=np.matmul(D,A)
G=np.matmul(B,D)
print("G=", G)
print("The condition number of a matrix A is", np.linalg.cond(A,2))
print("The condition number of a matrix G is",np.linalg.cond(G,2))
G= [[-0.001    1.       1.     ]
 [ 1.       0.78125  0.     ]
 [ 1.       0.       0.     ]]
The condition number of a matrix A is 13990.621644372157
The condition number of a matrix G is 4.656945664193629
In [ ]: