"Fossies" - the Fresh Open Source Software Archive

Member "ccmath-2.2.1/matrix/test/tpsinv.c" (16 Nov 2000, 1782 Bytes) of package /linux/misc/old/ccmath-2.2.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /*  tpsinv.c    CCMATH mathematics library source code.
    2  *
    3  *  Copyright (C)  2000   Daniel A. Atkinson    All rights reserved.
    4  *  This code may be redistributed under the terms of the GNU library
    5  *  public license (LGPL). ( See the lgpl.license file for details.)
    6  * ------------------------------------------------------------------------
    7  */
    8 /*
    9     Test:  psinv
   10 
   11     Uses:  mmul  mcopy  matprt
   12 
   13     Input file:  spdm.dat
   14 */
   15 #include "ccmath.h"
   16 void main(int na,char **av)
   17 { double *p,*a,*b,*c;
   18   int i,n; FILE *fp;
   19   if(na!=2){ printf("para: input_file\n"); exit(-1);}
   20   fp=fopen(*++av,"r");
   21   fscanf(fp,"%d",&n);
   22   a=(double *)calloc(3*n*n,sizeof(double));
   23   b=a+n*n; c=b+n*n;
   24   for(i=0,p=a; i<n*n ;++i) fscanf(fp,"%lf",p++);
   25   printf("Test of SPD Matrix Inverse\n");
   26   printf("  input matrix\n"); matprt(a,n,n,"%10f ");
   27   mcopy(b,a,n*n);
   28 
   29 /* invert a real symmetric positive definite matrix */
   30   i=psinv(a,n);
   31 
   32   if(i) printf("  singular input\n");
   33   else{
   34      printf("  inverse matrix\n"); matprt(a,n,n,"%10f ");
   35      printf("  product a*inverse\n"); mmul(c,b,a,n);
   36      matprt(c,n,n,"%12.9f ");
   37    }
   38 }
   39 /* Test output
   40 
   41 Test of SPD Matrix Inverse
   42   input matrix
   43   1.875000   0.625000   0.375000   1.125000 
   44   0.625000   1.875000   1.125000   0.375000 
   45   0.375000   1.125000   1.875000   0.625000 
   46   1.125000   0.375000   0.625000   1.875000 
   47   inverse matrix
   48   0.937500  -0.312500   0.187500  -0.562500 
   49  -0.312500   0.937500  -0.562500   0.187500 
   50   0.187500  -0.562500   0.937500  -0.312500 
   51  -0.562500   0.187500  -0.312500   0.937500 
   52   product a*inverse
   53  1.000000000 -0.000000000  0.000000000  0.000000000 
   54 -0.000000000  1.000000000 -0.000000000  0.000000000 
   55 -0.000000000 -0.000000000  1.000000000  0.000000000 
   56 -0.000000000 -0.000000000  0.000000000  1.000000000 
   57 */