/* cged.c -- Gaussian elimination linear equation solver for complex * double precision numbers. * (C)2001, C. Bond. All rights reserved. * * Simple pivoting on zero diagonal entry supported. * This version eliminates unnecessary zeroing of lower * triangular portion of source matrix. Does not scale * rows to unity pivot value. Swaps b[] as well as a[][], * so pivot ID vector is not required. */ #include #include int cged(complex **a,complex *b, complex *x, int n) { complex tmp,pvt,*t; int i,j,k,itmp; for (i=0;i=0;i--) { x[i]=b[i]; for (j=n-1;j>i;j--) { x[i] -= a[i][j]*x[j]; } x[i] /= a[i][i]; } return 0; } /* This version preserves the matrix 'a' and the vector 'b'. */ int cged2(complex **a,complex *b, complex *x, int n) { complex tmp,pvt,*t,**aa,*bb; int i,j,k,itmp,retval; // Initialize return value for successful execution. retval = 0; // Create and initialize working storage aa = new complex *[n]; bb = new complex [n]; for (i=0;i [n]; for (j=0;j=0;i--) { x[i]=bb[i]; for (j=n-1;j>i;j--) { x[i] -= aa[i][j]*x[j]; } x[i] /= aa[i][i]; } _100: for (i=0;i