lu_pp.m

来自「LU decomposition routines in matlab」· M 代码 · 共 63 行

M
63
字号
function [A, ipivt, iflag] = lu_pp( A );% % LU_PP  computes the LU--decomposition with partial% pivoting of a matrix A % % Usage%       [A, ipivt, iflag] = lu_pp( A )% % input:%        A:     the n by n matrix A% % output:%        A:     the LU-decomposition of  A% %        ipivt: pivot information% %        iflag: error flag%               iflag = 0  Row reductions could be performed,%                          A is upper triangular%               iflag = 1  dimension of A or of b is not correct% %% Matthias Heinkenschloss% Feb 24, 2001iflag = 0;% get size of A and check dimensions[m,n]    = size(A);if ( m ~= n )   iflag = 1;   returnend% Start LU--decompositionfor k = 1:n-1%  Find pivot index   [amax, i ] = max(abs(A(k:n,k)));   i          = i + k - 1;   ipivt(k)   = i;     %  Interchange rows if necessary   if( k ~= i )        tmp      = A(k,k:n);       A(k,k:n) = A(i,k:n);       A(i,k:n) = tmp;   end    if( amax > 0 )  % if amax == 0 subcolumn A(k:n,k) is zero       for i = k+1:n%          compute multipliers           A(i,k) = -A(i,k)/A(k,k);%          Perform row elimination           A(i,k+1:n) = A(i,k+1:n) + A(i,k) * A(k,k+1:n);       end   endend%end of lu_pp.m

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?