"Fossies" - the Fresh Open Source Software Archive

Member "ccmath-2.2.1/matrix/test/tchousv.c" (15 Nov 2000, 2483 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 /*  tchousv.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:  chousv
   10 
   11     Uses:  hconj  cmmul  cmprt
   12 
   13     Input File:  hm4.bin
   14 */
   15 #include "ccmath.h"
   16 char fmt[]="(%7.3f,%7.3f)";
   17 Cpx *r;
   18 void main(int na,char **av)
   19 { Cpx *a,*h,*u,*h1,*p;
   20   double *ev,*dp; int i,j,n;
   21   FILE *fb;
   22   if(na!=2){ printf("para: input_file\n"); exit(1);}
   23   fb=fopen(*++av,"rb");
   24   fread((void *)&n,sizeof(int),1,fb);
   25   a=(Cpx *)calloc(4*n*n,sizeof(Cpx));
   26   h=a+n*n; u=h+n*n; h1=u+n*n;
   27   ev=(double *)calloc(2*n,sizeof(double)); dp=ev+n;
   28   fread((void *)a,sizeof(Cpx),n*n,fb);
   29   printf(" mat a-in:\n"); cmprt(a,n,n,fmt);
   30 
   31 /* Householder rotation to tridiagonal with transformation matrix */
   32   chousv(a,ev,dp,n);
   33 
   34   printf("  evc:\n"); cmprt(a,n,n,fmt);
   35   for(i=0,p=h; i<n ;++i,p+=n+1){
   36     p->re=ev[i];
   37     if(i<n-1){ (p+1)->re=dp[i]; (p+n)->re=dp[i];}
   38    }
   39   printf(" td2:\n"); cmprt(h,n,n,fmt);
   40 
   41 /* check transformation matrix */
   42   cmcpy(u,a,n*n); hconj(u,n);
   43   cmmul(h1,h,a,n); cmmul(a,u,h1,n);
   44   printf(" evc^*ad*evc:\n"); cmprt(a,n,n,fmt);
   45 }
   46 /* Test output
   47 
   48  mat a-in:
   49 (  2.232, -0.000)( -0.073, -0.075)( -0.321,  0.030)(  0.379,  0.031)
   50 ( -0.073,  0.075)(  1.673,  0.000)( -0.102, -0.006)(  0.266, -0.178)
   51 ( -0.321, -0.030)( -0.102,  0.006)(  1.284,  0.000)(  0.143,  0.048)
   52 (  0.379, -0.031)(  0.266,  0.178)(  0.143, -0.048)(  1.812,  0.000)
   53   evc:
   54 (  1.000,  0.000)(  0.000,  0.000)(  0.000,  0.000)(  0.000,  0.000)
   55 (  0.000,  0.000)( -0.143, -0.147)( -0.631,  0.059)(  0.743,  0.062)
   56 (  0.000,  0.000)(  0.607,  0.269)(  0.474, -0.043)(  0.577, -0.019)
   57 (  0.000,  0.000)(  0.142,  0.705)( -0.445, -0.417)( -0.153, -0.295)
   58  td2:
   59 (  2.232,  0.000)(  0.509,  0.000)(  0.000,  0.000)(  0.000,  0.000)
   60 (  0.509,  0.000)(  1.340,  0.000)(  0.335,  0.000)(  0.000,  0.000)
   61 (  0.000,  0.000)(  0.335,  0.000)(  1.900,  0.000)(  0.132,  0.000)
   62 (  0.000,  0.000)(  0.000,  0.000)(  0.132,  0.000)(  1.528,  0.000)
   63  evc^*ad*evc:
   64 (  2.232,  0.000)( -0.073, -0.075)( -0.321,  0.030)(  0.379,  0.031)
   65 ( -0.073,  0.075)(  1.673, -0.000)( -0.102, -0.006)(  0.266, -0.178)
   66 ( -0.321, -0.030)( -0.102,  0.006)(  1.284,  0.000)(  0.143,  0.048)
   67 (  0.379, -0.031)(  0.266,  0.178)(  0.143, -0.048)(  1.812, -0.000)
   68 */