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

15 visualizzazioni (ultimi 30 giorni)
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 Commenti
infinity
infinity il 11 Ago 2019
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 il 11 Ago 2019
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 !

Accedi per commentare.

Risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by