How do we apply the Gaussian-Elimination method on this 5x5 Matrix/

조회 수: 15 (최근 30일)
Ahmed Saeed Mansour
Ahmed Saeed Mansour 2019년 8월 10일
댓글: Ahmed Saeed Mansour 2019년 8월 11일
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
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.
Ahmed Saeed Mansour
Ahmed Saeed Mansour 2019년 8월 11일
Thank you sir, the code of 3x3 is generalized after writting it without for loop. I checked out a solution of a random problem and it gave the correct answer. Okay you are right, I will study the code carefully and then I will extend it for the 5x5 matrix. If I reach the solution, I will post it here...
Vielen Dank !

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by