Skip to content
Snippets Groups Projects
Commit e723e6f6 authored by Mazouzi's avatar Mazouzi
Browse files

debut tp

parent 2940bc2b
No related branches found
No related tags found
No related merge requests found
import math
import numpy as np
import matplotlib.pyplot as plt
from scipy.linalg import lu
A=np.array([[1.,2.,3.],[0.,1.,2.],[0.,0.,1.]])
B=np.array([14.,8.,3.])
C=np.array([[1.,0.,0.],[1.,2.,0.],[1.,2.,1.]])
A = np.array([[1.,2.,3.],[0.,1.,2.],[0.,0.,1.]],dtype=np.float64)
B = np.array([15.,20.,8.])
C = np.array([[1.,0.,0.],[1.,2.,0.],[1.,2.,1.]],dtype=np.float64)
D = np.array([[1.,1.,4.],[1.,2.,5.],[1.,2.,1.]],dtype=np.float64)
def ResolutionRemontee(A,B):
......@@ -12,7 +14,7 @@ def ResolutionRemontee(A,B):
for i in range(0,n):
if (A[i,i] == 0):
return 0;
X=np.empty([n,1],dtype = np.float64)
X = np.empty([n],dtype = np.float64)
X[n-1] = B[n-1]/A[n-1][n-1]
for i in range(n-1,-1,-1):
......@@ -28,7 +30,7 @@ def ResolutionDescente(C,B):
for i in range(0,n):
if (C[i,i] == 0):
return 0;
X=np.empty([n,1],dtype = np.float64)
X = np.empty([n],dtype = np.float64)
X[1] = B[1]/C[1][1]
for i in range(0,n):
......@@ -39,5 +41,35 @@ def ResolutionDescente(C,B):
def GaussPivotPartiel(A,B):
I=np.array([[1,0,0],[0,1,0],[0,0,1]])
n = A.shape[0]
for i in range(0,n-1):
l = i
for k in range(i,n):
if(abs(A[k][i])>abs(A[l][i])):
l = k
if (l != i):
for j in range(i,n+1):
tmp = A[l][j]
A[l][j] = A[i][j]
A[i][j] = tmp
tmp = B[l]
B[l] = B[i]
B[i] = tmp
pivot = A[i][i]
for k in range(i+1,n):
factpivot = A[k][i]/pivot
A[k][i] = 0
for j in range(i+1,n):
A[k][j] = A[k][j] - factpivot*A[i][j]
B[k] = B[k] - factpivot * B[i]
return ResolutionRemontee(A,B)
print(GaussPivotPartiel(D,B))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment