MATLAB Answers

0

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

Asked by Katri Patol on 7 Apr 2019
Latest activity Edited by Katri Patol on 7 Apr 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

  0 Comments

Sign in to comment.

0 Answers