Error analysis in solution¶
In [5]:
from IPython.lib.display import YouTubeVideo
vid = YouTubeVideo("m8rUApZAD40")
display(vid)
Let us examine a system $$A=\begin{bmatrix} 10 & 7& 8& 7\\ 7& 5& 6& 5\\ 8 & 6& 10& 9\\ 7& 5& 10& 9\end{bmatrix}\quad b=\begin{bmatrix}32\\ 23\\ 33\\ 31\end{bmatrix}$$
In [34]:
import numpy as np
A = np.array([[10, 7, 8, 7], [7, 5, 6, 5], [8, 6, 10, 9], [7, 5, 9, 10]])
b = np.array([32,23, 33, 31])
x = np.linalg.solve(A,b)
print("x=",x)
x= [1. 1. 1. 1.]
If we now take the right hand side to be $$b=\begin{bmatrix}32.1\\ 22.9\\ 33.1\\ 30.9\end{bmatrix}$$
In [3]:
c=np.array([32.1,22.9, 33.1, 30.9])
x = np.linalg.solve(A,c)
print("x=",x)
x= [ 9.2 -12.6 4.5 -1.1]
In [35]:
eig=np.linalg.eigvalsh(A)
print("Eigenvalues=", eig)
Eigenvalues= [1.01500484e-02 8.43107150e-01 3.85805746e+00 3.02886853e+01]
If we solve a system with the matrix $$A=\begin{bmatrix} 10 & 7& 8.1 & 7.2 \\ 7.08 & 5.04 & 6& 5\\ 8 & 5.98 & 9.89 & 9\\ 6.99 & 4.99 & 9 & 9.98\end{bmatrix}\quad b=\begin{bmatrix}32\\ 23\\ 33\\ 31\end{bmatrix}$$
In [36]:
import numpy as np
A = np.array([[10, 7, 8.1, 7.2], [7.08, 5.04, 6, 5], [8, 5.98, 9.89, 9], [6.99, 4.99, 9, 9.98]])
b = np.array([32,23, 33, 31])
x = np.linalg.solve(A,b)
print("x=",x)
x= [-81. 137. -34. 22.]
Condition number of a regular matrix¶
In [4]:
vid = YouTubeVideo("DU08gjV9W6M")
display(vid)
If we have $$A=\begin{bmatrix} 4.1 & 2.8\\ 9.7 & 6.6\end{bmatrix} \quad b=\begin{bmatrix} 4.1\\ 9.7 \end{bmatrix}$$
In [38]:
import numpy as np
A = np.array([[4.1, 2.8], [9.7, 6.6]])
b = np.array([4.1,9.7])
x = np.linalg.solve(A,b)
print("x=",x)
x= [1. 0.]
If we take $$c=\begin{bmatrix} 4.11\\ 9.70 \end{bmatrix}$$
In [39]:
c=np.array([4.11,9.70])
x = np.linalg.solve(A,c)
print("x=",x)
X= [0.34 0.97]
Calculate the condition number in a norm 1!
In [ ]: