You are on page 1of 1

%% Solution of x in Ax=b using Gauss Method

clear all;
close all;
n=input('donner la taille de la matrice');
a=input('Donner la matrice a : \n');
b=input('Donner le vecteur b : \n');
%a=[1 5 8;2 -4 10;6 2 -5]
%b=[5;1;3]
A=[a b]
n=size(A,1)
for k=1:n-1
for i=k+1:n
w=A(i,k)/A(k,k)
for j=k:n+1
A(i,j)=A(i,j)-w*A(k,j)
end
end
end
A
for i=n:-1:1
s=0;
for j=i+1:n
s=s+A(i,j)*x(j);
end
x(i)=(A(i,n+1)-s)/A(i,i)
end
x

You might also like