CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Guest

    Partial Pivoting for Gaussian Elimination

    I need to write a subprogram that adds partial pivoting to the basic gaussian elimination program
    [email protected]


  2. #2
    Join Date
    Aug 1999
    Location
    Denmark
    Posts
    26

    Re: Partial Pivoting for Gaussian Elimination

    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


  3. #3
    Join Date
    Aug 1999
    Posts
    1

    Re: Partial Pivoting for Gaussian Elimination

    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
    [email protected]


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured