« Gauss partial pivoting » to « Gauss complete pivoting »

5 Ansichten (letzte 30 Tage)
amine aquesbi
amine aquesbi am 20 Jan. 2020
Hello, I want to make this gauss partial pivoting into a gauss complete pivoting but I can't fix it ... Can you help me with it please ?
% Gaussian inversion with pivoting 11/10/2019
function x=mygausspivot(A,b)
if size(A,1) ~= size(A,2)
error('Matrix is not square!)');
end;
n=size(A,1);
% Matrix triangualisation:
for i=1:n
% Searching for the pivoting line
% disp([ 'Treatment of line i=' num2str(i) ] );
n_max=i;
for m=i:n
if abs(A(n_max,i)) < abs(A(m,i))
n_max=m;
end
end
% disp([ 'Line with pivoting element n_max=' num2str(n_max) ] );
% exchangement of line i and pivoting line n_max in the matrix A and in the vector b
for l=i:n
tmp=A(i,l);
A(i,l)=A(n_max,l);
A(n_max,l)=tmp;
end
tmp=b(i);
b(i)=b(n_max);
b(n_max)=tmp;
p=A(i,i); % pivoting element
% verification of non-generation of matrix
if p==0
disp('Pivoting element is zero (matrix could be degenerated)!!!');
% error('Pivoting element is zero (matrix degenerated?)');
end
for k=i:n
A(i,k)=A(i,k)/p;
end
b(i)=b(i)/p;
for j=i+1:n
r=A(j,i);
for k=i:n
A(j,k)=A(j,k)-A(i,k)*r;
end
b(j)=b(j)-b(i)*r;
end
end
% In this point our matrix is, normally, upper triangular
% (with ones on the diaganonal),
% and we solving the folowing liniar equation:
% 1 a_12 ... a_1N x_1 b_1
% 0 1 ... a_2N * x_2 = b_2
% 0 0 ......... . .
% 0 0 ... 1 x_N b_N
% x calculation from triangular matrix:
x=b;
for i=n-1:-1:1
for k=i+1:n
x(i)=x(i)-x(k)*A(i,k);
end
end
% now x containes the solution
end

Antworten (0)

Kategorien

Mehr zu Linear Algebra finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by