1 /*  tcmops.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:  cmattr  trncm
10 
11     Uses:  cmmult  cmprt
12 
13     Input file:  cm42.dat
14 */
15 #include "ccmath.h"
16 char cfmt[]="(%7.3f,%7.3f)";
main(int na,char ** av)17 void main(int na,char **av)
18 { Cpx *a,*b,*c,*p;
19   int i,j,n,m; FILE *fp;
20   if(na!=2){ printf("para: input_file\n"); exit(-1);}
21   fp=fopen(*++av,"r");
22   fscanf(fp,"%d %d",&n,&m);
23   b=(Cpx *)calloc(2*n*m,sizeof(Cpx)); c=b+n*m;
24   a=(Cpx *)calloc(n*n,sizeof(Cpx));
25   for(i=0,p=b; i<n ;++i){
26     for(j=0; j<m ;++j,++p) fscanf(fp,"%lf %lf",&(p->re),&(p->im));
27    }
28 
29   printf(" Mat b:\n"); cmprt(b,n,m,cfmt);
30 
31 /* general complex transpose */
32   cmattr(c,b,n,m);
33 
34   printf(" Mat b':\n"); cmprt(c,m,n,cfmt);
35   for(i=0,p=c; i<n*m ;++i,++p) p->im= -(p->im);
36   cmmult(a,b,c,n,m,n);
37   printf(" Mat a=b*b^:\n"); cmprt(a,n,n,cfmt);
38 
39 /* square matrix transpose */
40   trncm(a,n);
41 
42   printf(" Mat a':\n"); cmprt(a,n,n,cfmt);
43 }
44 /* Test output
45 
46  Mat b:
47 ( -0.542,  1.345)( -0.830, -1.434)
48 ( -2.256,  0.567)( -1.018, -0.849)
49 ( -0.832,  0.843)( -0.999, -1.059)
50 (  0.147,  0.758)(  0.673, -0.536)
51  Mat b':
52 ( -0.542,  1.345)( -2.256,  0.567)( -0.832,  0.843)(  0.147,  0.758)
53 ( -0.830, -1.434)( -1.018, -0.849)( -0.999, -1.059)(  0.673, -0.536)
54  Mat a=b*b^:
55 (  4.848,  0.000)(  4.048, -1.972)(  3.933, -0.109)(  1.150, -0.801)
56 (  4.048,  1.972)(  7.168,  0.000)(  4.271,  1.200)( -0.132,  0.676)
57 (  3.933,  0.109)(  4.271, -1.200)(  3.522,  0.000)(  0.412, -0.494)
58 (  1.150,  0.801)( -0.132, -0.676)(  0.412,  0.494)(  1.336,  0.000)
59  Mat a':
60 (  4.848,  0.000)(  4.048,  1.972)(  3.933,  0.109)(  1.150,  0.801)
61 (  4.048, -1.972)(  7.168,  0.000)(  4.271, -1.200)( -0.132, -0.676)
62 (  3.933, -0.109)(  4.271,  1.200)(  3.522,  0.000)(  0.412,  0.494)
63 (  1.150, -0.801)( -0.132,  0.676)(  0.412, -0.494)(  1.336,  0.000)
64 */
65