/************************************************************************* Copyright (c) 1992-2007 The University of Tennessee. All rights reserved. Contributors: * Sergey Bochkanov (ALGLIB project). Translation from FORTRAN to pseudocode. See subroutines comments for additional copyrights. >>> SOURCE LICENSE >>> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation (www.fsf.org); either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. A copy of the GNU General Public License is available at http://www.fsf.org/licensing/licenses >>> END OF LICENSE >>> *************************************************************************/ using System; namespace alglib { public class clu { /************************************************************************* LU decomposition of a complex general matrix of size MxN The subroutine calculates the LU decomposition of a rectangular general matrix with partial pivoting (with row permutations). Input parameters: A - matrix A whose indexes range within [0..M-1, 0..N-1]. M - number of rows in matrix A. N - number of columns in matrix A. Output parameters: A - matrices L and U in compact form (see below). Array whose indexes range within [0..M-1, 0..N-1]. Pivots - permutation matrix in compact form (see below). Array whose index ranges within [0..Min(M-1,N-1)]. Matrix A is represented as A = P * L * U, where P is a permutation matrix, matrix L - lower triangular (or lower trapezoid, if M>N) matrix, U - upper triangular (or upper trapezoid, if M=0 & n>=0, "Error in LUDecomposition: incorrect function arguments"); // // Quick return if possible // if( m==0 | n==0 ) { return; } for(j=0; j<=Math.Min(m-1, n-1); j++) { // // Find pivot and test for singularity. // jp = j; for(i=j+1; i<=m-1; i++) { if( (double)(AP.Math.AbsComplex(a[i,j]))>(double)(AP.Math.AbsComplex(a[jp,j])) ) { jp = i; } } pivots[j] = jp; if( a[jp,j]!=0 ) { // //Apply the interchange to rows // if( jp!=j ) { for(i_=0; i_<=n-1;i_++) { t1[i_] = a[j,i_]; } for(i_=0; i_<=n-1;i_++) { a[j,i_] = a[jp,i_]; } for(i_=0; i_<=n-1;i_++) { a[jp,i_] = t1[i_]; } } // //Compute elements J+1:M of J-th column. // if( j=0 & n>=0, "Error in ComplexLUDecomposition: incorrect function arguments"); // // Quick return if possible // if( m==0 | n==0 ) { return; } for(j=1; j<=Math.Min(m, n); j++) { // // Find pivot and test for singularity. // jp = j; for(i=j+1; i<=m; i++) { if( (double)(AP.Math.AbsComplex(a[i,j]))>(double)(AP.Math.AbsComplex(a[jp,j])) ) { jp = i; } } pivots[j] = jp; if( a[jp,j]!=0 ) { // //Apply the interchange to rows // if( jp!=j ) { for(i_=1; i_<=n;i_++) { t1[i_] = a[j,i_]; } for(i_=1; i_<=n;i_++) { a[j,i_] = a[jp,i_]; } for(i_=1; i_<=n;i_++) { a[jp,i_] = t1[i_]; } } // //Compute elements J+1:M of J-th column. // if( ji ) { l[i,j] = 0; } if( j==i ) { l[i,j] = 1; } if( j=i ) { u[i,j] = a[i,j]; } } } } } }