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

2 次查看(过去 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 个)

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differential Equations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by