How do we apply the Gaussian-Elimination method on this 5x5 Matrix/
10 次查看(过去 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 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!