Questo sito contribuisce alla audience di

## Matlab Pubblicato in: M-Files

## Gaussian elimination with partial pivoting

Risoluzione di un sistema lineare di equazione attraverso la tecnica del partial pivotin di Gauss

function x = GaussPP(A,b)

%GaussPP(A,b) solves the n-by-n linear system of equations using partial
%pivoting
%A is the coeficient matrix
%b the right-hand column vector

%This file was generated after following a course in numerical analysis
%at the University of Pretoria
%The present partial pivoting function follows the algorithmic guidelines
%given in the book of Burden & Faires, Numerical Analysis, 7th ed.

%Author: Alain G. Kapitho
%Date : Nov 2005

n = size(A,1); %getting n
A = [A,b]; %produces the augmented matrix

%elimination process starts
for i = 1:n-1
p = i;
%comparison to select the pivot
for j = i+1:n
if abs(A(j,i)) > abs(A(i,i))
U = A(i,:);
A(i,:) = A(j,:);
A(j,:) = U;
end
end
%cheking for nullity of the pivots
while A(p,i)== 0 & p <= n
p = p+1;
end
if p == n+1
disp(’No unique solution’);
break
else
if p ~= i
T = A(i,:);
A(i,:) = A(p,:);
A(p,:) = T;
end
end

for j = i+1:n
m = A(j,i)/A(i,i);
for k = i+1:n+1
A(j,k) = A(j,k) - m*A(i,k);
end
end
end

%checking for nonzero of last entry
if A(n,n) == 0
disp(’No unique solution’);
return
end

%backward substitution
x(n) = A(n,n+1)/A(n,n);
for i = n - 1:-1:1
sumax = 0;
for j = i+1:n
sumax = sumax + A(i,j)*x(j);
end
x(i) = (A(i,n+1) - sumax)/A(i,i);
end

### Ultimi interventi

• 22 Jan 2011

#### La varibile nargin in Matlab

• 21 Jan 2011

#### esempio di una funzione Matlab

• 20 Jan 2011

Vedi tutti