Clear Filters
Clear Filters

Gauss elimination method- I am not getting the right answer can anyone help me here

1 view (last 30 days)
clear all
clc
A=[1 4 -1;1 1 -6;3 -1 -1];
b=[-5;-12;4];
%Solve the linear system Ax=B
[n,~]=size(A);
x=zeros(n,1);
%matrix A to upper triangular matrix
for i=1:n-1
m=A(i+1:n,i)/A(i,i);
A(i+1:n,:)-m*A(i,:);
b(i+1:n,:)=b(i+1:n,:)-m*b(i,:);% we are only considering about row
end
%back substitution
x(n,:)=b(n,:)/A(n,n);
for i= n:-1:1
t = b(i,:);
for j = n:-1:i
t = t-(A(i,j)*x(j,:))
end
x(i,:) = t/A(i,i);
end
x

Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!