gauasspivot elimination methode important
24 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
% solving linear equation
clc
clear
%system wanted to be solved
A=[0,0,1,0,-6;
0,0,0,3,-3;
2,-11,8,1,0;
4,0,0,-1,-3;
0,0,9,-1,0] % coefficient matrix
b=[-50;0;0;0;160]% right handside matrix
%Gauss elimination method with pivoting
x=GaussPivot(A,b);
disp('Gauss elimnation method with pivoting')
x
function [x] = GaussPivot(A,b)
%GAUSS - Gauss elimination with pivoting
%to solve a system of linear equations Ax=b
%
n=size(A,1);
x=zeros(n,1);
A=[A,b]; % augmented matrix
for k=1:(n-1)
%pivoting
if A(k,k)==0
MaxPivot=A(k,k);
for i=k+1:n
if abs(A(i,k))>MaxPivot
iMaxPivot=i;
MaxPivot=abs(A(i,k));
end
end
TempA=A(k,:);
A(k,:)=A(iMaxPivot,:);
A(iMaxPivot,:)=TempA;
end
%end pivoting
for i=(k+1):n
A(i,:)=A(i,:)-A(i,k)/A(k,k)*A(k,:);
end
end
b=A(:,n+1);
%backward substitution
x(n)=b(n)/A(n,n);
for i=n-1:-1:1
x(i)=(b(i)-A(i,i+1:n)*x(i+1:n))/A(i,i);
end
0 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur Numerical Integration and Differential Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!