How do we apply the Gaussian-Elimination method on this 5x5 Matrix/
조회 수: 39(최근 30일)
표시 이전 댓글
Hell, I have this matrix:
A=[300 -100 0 0 0 ; -100 200 -100 0 0 ; 0 -100 200 -100 0 ; 0 0 -100 200 -100; 0 0 0 -100 300 ];
b=[20000;0;0;0;80000];
How can we solve it using Gaussian- Elimination method?
I have a code that applies it but foe a 3x3 matrix:
Thank you
A=[1 1 -1 ; 0 1 3 ; -1 0 -2 ];
b=[9;3;2];
% Solve Ax=b Gauss Elimination
Ab=[A,b];
n=3;
% A(1,1) as a pivot element
alpha=Ab(2,1)/Ab(1,1);
Ab(2,:)=Ab(2,:)-alpha*Ab(1,:);
alpha=A(3,1)/A(1,1);
Ab(3,:)=Ab(3,:)-alpha*Ab(1,:);
% A(2,2) as a pivot element
alpha= Ab(3,2)/Ab(2,2);
Ab(3,:)=Ab(3,:)-alpha*Ab(2,:);
Ab
%Back-Substitution
n=3;
x=zeros(3,1);
for i=3:-1:1
x(i)=(Ab(i,end)- Ab(i,i+1:n)*x(i+1:n) ) / Ab(i,i);
end
x
답변(0개)
참고 항목
범주
Find more on Matrix Indexing 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!