Solve by using gaussian elimination
x+2y-3z=-1
-3x+y-2z=-7
5x+3y-4z=2
close all,
clear all,
clc,
% x + 2y - 3z =-1
% -3x + y - 2z =-7
% 5x + 3y - 4z = 2
C = [1, 2, -3;-3, 1, -2;5, 3, -4];
b = [-1, -7, 2]';
dett = det(C)
if dett == 0
fprintf('No Solution possible as det(C) = 0 ')
else
b = b';
A = [ C b ];
for j = 1:(n-1)
for i= (j+1) : n
mult = A(i,j)/A(j,j) ;
for k= j:n+1
A(i,k) = A(i,k) - mult*A(j,k) ;
end
end
end
for p = n:-1:1
for r = p+1:n
x(p) = A(p,r)/A(p,r-1)
end
end
disp('Solution using Gauss-Elimination Method');
x
end
Comments
Leave a comment