From d112fff1d525cd42f1a2fb5c431259f25ab6e39e Mon Sep 17 00:00:00 2001 From: Mazouzi <janet.mazouzi@polytech-lille.net> Date: Mon, 19 Apr 2021 15:54:47 +0200 Subject: [PATCH] TP presque fini --- tp4/MethodeGaussPivotPartiel.py | 51 ++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/tp4/MethodeGaussPivotPartiel.py b/tp4/MethodeGaussPivotPartiel.py index a569258..1c6d619 100644 --- a/tp4/MethodeGaussPivotPartiel.py +++ b/tp4/MethodeGaussPivotPartiel.py @@ -67,9 +67,58 @@ def GaussPivotPartiel(A,B): return ResolutionRemontee(A,B) -print(GaussPivotPartiel(D,B)) +def Cholesky(A,B): + n = A.shape[0] + S1 = 0 + S2 = 0 + L = np.empty([n,n],dtype = np.float64) + L[0][0] = math.sqrt(A[0][0]) + for i in range(1,n): + L[i][0] = A[i][0]/L[0][0] + + for j in range(1,n): + for i in range(0,j): + L[i][j] = 0 + S1 = S1 + (L[j][i])**2 + L[j][j] = math.sqrt((A[j][j]-S1)) + S1 = 0 + for i in range(j+1,n): + for k in range(1,n): + S2 = S2 + L[i,k]*L[j,k] + L[i][j] = (A[i][j] - S2)/L[j][j] + S2 = 0 + return L + + +#print(GaussPivotPartiel(D,B)) + +''' +A = np.array([[2.,4.,4.],[1.,3.,1.],[1.,5.,6.]],dtype=np.float64) +B = np.array([2.,1.,-6.]) + +[E,L,U]=lu(A) +#print(E) +print(np.transpose(E)) +print(B) +C = np.multiply(np.transpose(E),B) +#Y = ResolutionDescente(L,np.transpose(E)*B) +print(C) +#print(ResolutionRemontee(U,Y)) +''' + + +A = np.array([[9.,6.,3.],[6.,20.,6.],[3.,6.,3.]],dtype=np.float64) +B = np.array([39.,86.,27.]) + +print(Cholesky(A,B)) +L=Cholesky(A,B) +Bb = ResolutionDescente(L,B) +X = ResolutionRemontee(np.transpose(L),Bb) + +print(X) + -- GitLab