I can't make my gauss elimination code with partial pivoting

3 visualizaciones (últimos 30 días)
Katri Patol
Katri Patol el 7 de Abr. de 2019
Editada: Katri Patol el 7 de Abr. de 2019
I wrote naive gauss elmination code, now i need to convert it to partial pivot gauss elimination . but i cant figure out how to do it. can you help me pls. here is my code
clc,clear,clear all
% gauss elimination method
A=[0.1 6 -0.4; 0.4 -0.3 8;3 -0.1 -0.2];
b=[-15.5;51.2;6.2];
[m,n]=size(A);
if(m~=n)
error('coefficient matrix must be square');
end
nb=n+1;
Aug=[A b];
%forward elimination
for k=1:n-1
for i=k+1:n
factor=Aug(i,k)/Aug(k,k);
Aug(i,k:nb)=Aug(i,k:nb)-factor*Aug(k,k:nb);
end
end
x=zeros(n,1);
x(n)=Aug(n,nb)/Aug(n,n);
%back substution
for i=n-1:-1:1;
x(i)=(Aug(i,nb)-Aug(i,i+1:n)*x(i+1:n))/Aug(i,i);
end
fprintf('RESULTS \n');
for i=1:3
fprintf('x(%d)=%8.6f\n',i,x(i));
end

Respuestas (0)

Categorías

Más información sobre Numerical Integration and Differential Equations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by