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

2 ビュー (過去 30 日間)
Amith Anoop Kumar
Amith Anoop Kumar 2020 年 11 月 14 日
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 Center および File ExchangeNumerical 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