Gauss elimination method- I am not getting the right answer can anyone help me here
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!