How do we apply the Gaussian-Elimination method on this 5x5 Matrix/
조회 수: 15 (최근 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
댓글 수: 2
infinity
2019년 8월 11일
Perhaps, you take time to understand the code for 3x3 matrix first. Then, you can extend this method for higher dimension.
However, there is a point in the code for 3x3 matrix might lead to error. For example, if Ab(1,1) or Ab(2,2) equals zeros. To avoid this, you should refer more details of this method.
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!