Gauss elimination method- I am not getting the right answer can anyone help me here
2 views (last 30 days)
Show older comments
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
0 Comments
Answers (0)
See Also
Categories
Find more on Numerical Integration and Differential Equations 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!