]> AND Private Git Repository - cours-mesi.git/blob - tps/chap1/tpcond.py
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
typos
[cours-mesi.git] / tps / chap1 / tpcond.py
1 import numpy as np
2
3 A = np.array([[4,1,0,0],[1,4,1,0],[0,1,4,1],[0,0,1,4]])
4 Ap = np.array([[4,1,0.1,0.2],[1.08,4.04,1,0],[0,0.98,3.89,1],[-0.1,-0.1,1,3.98]])
5 B = np.array([[5],[6],[6],[5]])
6 Bp = np.array([[5.1],[5.9],[6.1],[4.9]])
7
8 X1 = np.linalg.solve(A,B)
9 X2 = np.linalg.solve(A,Bp)
10 X3 = np.linalg.solve(Ap,B)
11
12 print X1,X2,X3
13 print np.linalg.cond(A)
14
15
16 A = np.array([[10,7,8,7],[7,5,6,5],[8,6,10,9],[7,5,9,10]])
17 Ap = np.array([[10,7,8.1,7.2],[7.08,5.04,6,5],[8,5.98,9.98,9],[6.99,4.99,9,9.98]])
18
19 B = np.array([[32],[23],[33],[31]])
20 B = np.array([[32.1],[22.9],[33.1],[30.9]])
21
22 X1 = np.linalg.solve(A,B)
23 X2 = np.linalg.solve(A,Bp)
24 X3 = np.linalg.solve(Ap,B)
25
26 print X1,X2,X3
27 print np.linalg.cond(A)