Click to See Complete Forum and Search --> : Partial Pivoting for Gaussian Elimination


August 16th, 1999, 08:41 AM
I need to write a subprogram that adds partial pivoting to the basic gaussian elimination program
tpugh@uci.edu

Jeep
August 16th, 1999, 08:54 AM
Hi,

I once wrote a program in MatLab which does Gaussian elimination with complete pivoting. Maybe it can give you some ideas:


function [L,U,P,Q] = gecp(A)
%GECP Gaussian elimination with complete pivoting.
% [L,U,P,Q] = GECP(A) computes the factorization P*A*Q = L*U,
% where L is unit lower triangular, U is upper triangular,
% and P and Q are permutation matrices.
% By itself, GECP(A) returns the final reduced matrix from the
% elimination containing both L and U.

[n, n] = size(A);
pp = 1:n; qq = 1:n;

for k = 1:n-1

% Find largest element in remaining square submatrix.
% Note: when tie for max, no guarantee which element is chosen.
[colmaxima, rowindices] = max( abs(A(k:n, k:n)) );
[biggest, colindex] = max(colmaxima);
row = rowindices(colindex)+k-1; col = colindex+k-1;

% Permute largest element into pivot position.
A( [k, row], : ) = A( [row, k], : );
A( :, [k, col] ) = A( :, [col, k] );
pp( [k, row] ) = pp( [row, k] ); qq( [k, col] ) = qq( [col, k] );

if A(k,k) == 0
break
end

A(k+1:n,k) = A(k+1:n,k)/A(k,k); % Multipliers.

% Elimination
i = k+1:n;
A(i,i) = A(i,i) - A(i,k) * A(k,i);

end

if nargout <= 1
L = A;
return
end

L = tril(A,-1) + eye(n);
U = triu(A);

if nargout >= 3, P = eye(n); P = P(pp,:); end
if nargout >= 4, Q = eye(n); Q = Q(:,qq); end





Good Luck, Jeep

Tyler Pugh
August 16th, 1999, 09:30 AM
Jeep,
Do you have any ideas about how to write a partial pivot subprogram with it called this: pivot(int n, float A[10][11], int i) where A is an n by n+1 real array, and i is an input integer indicating the i-th elimination?
Tyler Pugh
tpugh@uci.edu