home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / fractal / kaos.lha / eigenlib / driver.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-18  |  4.2 KB  |  110 lines

  1. main()
  2.  
  3. {
  4. int i,n,nm,count,*iv1,matz,ierr,*ivector();
  5. double **a,**z,*fv1,*wr,*wi;
  6. double rg(),**dmatrix(),*dvector();
  7.                    
  8. /*
  9.  
  10.   
  11.   this routine serves as a test driver for the c version of the 
  12.   eispack eigenvector routines.
  13.       on input :
  14.  
  15.          nm  must be set to the row dimension of the two-dimensional
  16.          array parameters as declared in the calling program
  17.          dimension statement.
  18.  
  19.          n  is the order of the matrix  a.
  20.  
  21.          a  contains the real general matrix.
  22.  
  23.          matz  is an integer variable set equal to zero if
  24.          only eigenvalues are desired.  otherwise it is set to
  25.          any non-zero integer for both eigenvalues and eigenvectors.
  26.  
  27.       on output
  28.  
  29.          wr  and  wi  contain the real and imaginary parts,
  30.          respectively, of the eigenvalues.  complex conjugate
  31.          pairs of eigenvalues appear consecutively with the
  32.          eigenvalue having the positive imaginary part first.
  33.  
  34.          z  contains the real and imaginary parts of the eigenvectors
  35.          if matz is not zero.  if the j-th eigenvalue is real, the
  36.          j-th column of  z  contains its eigenvector.  if the j-th
  37.          eigenvalue is complex with positive imaginary part, the
  38.          j-th and (j+1)-th columns of  z  contain the real and
  39.          imaginary parts of its eigenvector.  the conjugate of this
  40.          vector is the eigenvector for the conjugate eigenvalue.
  41.  
  42.          ierr  is an integer output variable set equal to an error
  43.             completion code described in the documentation for hqr
  44.             and hqr2.  the normal completion code is zero.
  45.  
  46.          iv1  and  fv1  are temporary storage arrays.                 
  47.  
  48.     written by :  m. myers            last change :  5 september 1989    */
  49.  
  50. a=dmatrix(1,8,1,8);
  51. z=dmatrix(1,8,1,8);
  52. wr=dvector(1,8);
  53. wi=dvector(1,8);
  54. iv1=ivector(1,15000);
  55. fv1=dvector(1,15000);
  56. nm = 8;
  57. n = 8;
  58. matz=1; 
  59.  
  60. a[1][1] = -31.e0  ;  a[1][2] = 96.e0  ;  a[1][3] = 84.e0  ;  a[1][4] = -96.e0;
  61. a[1][5] = -240.e0 ;  a[1][6] = 384.e0 ;  a[1][7] = 0.e0   ;  a[1][8] = 0.e0;
  62. a[2][1] = -30.e0  ;  a[2][2] = 74.e0  ;  a[2][3] = 45.e0  ;  a[2][4] = -60.e0;
  63. a[2][5] = -150.e0 ;  a[2][6] = 240.e0 ;  a[2][7] = 0.e0   ;  a[2][8] = 0.e0;
  64. a[3][1] = -12.e0  ;  a[3][2] =  6.e0  ;  a[3][3] =-25.e0  ;  a[3][4] = 24.e0;
  65. a[3][5] =  60.e0  ;  a[3][6] = -96.e0 ;  a[3][7] = 0.e0   ;  a[3][8] = 0.e0;
  66. a[4][1] = -12.e0  ;  a[4][2] = 18.e0  ;  a[4][3] = -6.e0  ;  a[4][4] = 43.e0;
  67. a[4][5] =   85.e0 ;  a[4][6] =-145.e0 ;  a[4][7] = 0.e0   ;  a[4][8] = 0.e0;
  68. a[5][1] = -36.e0  ;  a[5][2] = 54.e0  ;  a[5][3] =-18.e0  ;  a[5][4] = 66.e0;
  69. a[5][5] =  102.e0 ;  a[5][6] =-174.e0 ;  a[5][7] = 0.e0   ;  a[5][8] = 0.e0;
  70. a[6][1] = -24.e0  ;  a[6][2] = 36.e0  ;  a[6][3] =-12.e0  ;  a[6][4] = 50.e0;
  71. a[6][5] =   80.e0 ;  a[6][6] =-137.e0 ;  a[6][7] = 0.e0   ;  a[6][8] = 0.e0;
  72. a[7][1] =   0.e0  ;  a[7][2] =  0.e0  ;  a[7][3] =  0.e0  ;  a[7][4] =   0.e0;
  73. a[7][5] =    0.e0 ;  a[7][6] =   0.e0 ;  a[7][7] = -1.e0  ;  a[7][8] = 1.e0  ;
  74. a[8][1] =   0.e0  ;  a[8][2] =  0.e0  ;  a[8][3] =  0.e0  ;  a[8][4] =   0.e0;
  75. a[8][5] =    0.e0 ;  a[8][6] =   0.e0 ;  a[8][7] = 4.e0   ;  a[8][8] = 2.e0;
  76.  
  77. printf("a matrix : \n----------\n");
  78. for (i=1;i<=8;i++)
  79.  {printf("%7.2f  %7.2f  %7.2f  %7.2f  ",a[i][1],a[i][2],a[i][3],a[i][4]);
  80.   printf("%7.2f  %7.2f  %7.2f  %7.2f  \n",a[i][5],a[i][6],a[i][7],a[i][8]);}
  81.  
  82.  
  83. ierr=rg(nm,n,a,wr,wi,matz,z,iv1,fv1);
  84.  
  85. count = 1;
  86. printf("\n \n \n C-Source Version of the EISPACK Eigenvalue/Eigenvector Routines \n");
  87. printf(" --------------------------------------------------------------- \n \n");
  88.  
  89. while (count <= nm)
  90.  { if (wi[count] == 0.e0)
  91.      {printf("\n \n Real Eigenvalue : %8.4f \n", wr[count]);
  92.       if (matz != 0)
  93.         for (i=1;i<=nm;i++)
  94.           printf("      ( %8.4f ) \n",z[i][count]); 
  95.       count = count + 1;}
  96.    else
  97.      {printf("\n \n Complex Eigenvalue :  %8.4f + %8.4f i \n \n",wr[count],wi[count]);
  98.       if (matz != 0)
  99.         for (i=1;i<=nm;i++)
  100.           printf("      ( %8.4f + %8.4f i  ) \n",z[i][count],z[i][count+1]); 
  101.       printf("\n \n Complex Eigenvalue :  %8.4f + %8.4f i \n \n",wr[count+1],wi[count+1]);
  102.       if (matz != 0)
  103.         for (i=1;i<=nm;i++)
  104.            printf("      ( %8.4f - %8.4f i  ) \n",z[i][count],z[i][count+1]); 
  105.       count = count + 2;
  106.      }
  107.  }
  108. }   
  109.  
  110.