home *** CD-ROM | disk | FTP | other *** search
- # include <math.h>
- # include "complex.h"
- # include "matmath.h"
- # include <stdio.h>
-
-
- float mat1[3][3];
- float mat2[3][3];
- float mat3[3][3];
- float vec1[100];
- int order;
- float det;
- float vm;
- char err;
- int i;
- int j;
- int k;
- char message[80];
-
- float a[4][4];
- float ev[4][4];
- float eigenvalues[4];
-
- int n;
- int count;
- char success;
- char c;
-
-
-
-
- main()
- {
-
- mat1[0][0] = 13.0;
- mat1[0][1] = -8.0;
- mat1[0][2] = -3.0;
- mat1[1][0] = -8.0;
- mat1[1][1] = 10.0;
- mat1[1][2] = -1.0;
- mat1[2][0] = -3.0;
- mat1[2][1] = -1.0;
- mat1[2][2] = 11.0;
-
- mat2[0][0] = 1.0;
- mat2[0][1] = 5.0;
- mat2[0][2] = 1.0;
- mat2[1][0] = 3.0;
- mat2[1][1] = 6.0;
- mat2[1][2] = 3.0;
- mat2[2][0] = 0.0;
- mat2[2][1] = 1.0;
- mat2[2][2] = -9.0;
- MatProd(&mat1[0][0],&mat2[0][0],3,3,3,&mat3[0][0]);
- strcpy(message, "matrix product mat1 x mat2 = ");
- MatPrint(&mat3[0][0],3,3,message);
- printf("press carriage return to advance to next procedure \n");
- c = getch();
- printf("\n");
- vm = 11;
- MatScalarProd(&mat1[0][0],vm,3,3,&mat3[0][0]);
- printf("%s %8.3f\n", message, vm);
- printf("\n");
- strcpy( message, "matrix scaler product mat1 x ");
- MatPrint(&mat3[0][0],3,3,message);
- printf( "press carriage return to advance to next procedure \n");
- c = getch();
- printf("\n");
- MatAdd(&mat1[0][0],&mat2[0][0],3,3,&mat3[0][0]);
- strcpy( message, "matrix add mat1 + mat 2 = ");
- MatPrint(&mat3[0][0],3,3,message);
- printf("press carriage return to advance to next procedure \n");
- c = getch();
- printf("\n");
- MatTranspose(&mat1[0][0],3,3,&mat3[0][0]);
- strcpy( message, "matrix transpose of mat1 = ");
- MatPrint(&mat3[0][0],3,3,message);
- printf( "press carriage return to advance to next procedure \n");
- c = getch();
- printf("\n");
- det = MatDeter(&mat1[0][0],3);
- printf("determinant of matrix mat1 = %10.3f\n", det);
- printf("\n");
- printf("press carriage return to advance to next procedure \n");
- c = getch();
- printf("\n");
- MatInvert(&mat1[0][0],3,&det,&mat3[0][0]);
- strcpy( message, "inverse of matrix mat1 = ");
- MatPrint(&mat3[0][0],3,3,message);
- printf( "determinant of matrix mat1 = %10.3f\n", det);
- printf("\n");
-
- printf("%s\n", "press carriage return to begin Jacobi Demo ");
- c = getch();
- printf("\n");
- n = 4;
- a[0][0] = 5.0;
- a[0][1] = 4.0;
- a[0][2] = 1.0;
- a[0][3] = 1.0;
- a[1][0] = 4.0;
- a[1][1] = 5.0;
- a[1][2] = 1.0;
- a[1][3] = 1.0;
- a[2][0] = 1.0;
- a[2][1] = 1.0;
- a[2][2] = 4.0;
- a[2][3] = 2.0;
- a[3][0] = 1.0;
- a[3][1] = 1.0;
- a[3][2] = 2.0;
- a[3][3] = 4.0;
-
- count = 10;
- CyclicJacobi(&a[0][0],n,&eigenvalues[0],&ev[0][0],&count,&success);
- NormalizeEigenVectors(&ev[0][0],n);
- printf("Success %d\n", success);
- for ( i = 0; i <= n-1; ++i ) {
- printf("Eigenvalue %d = %8.3f\n", i, eigenvalues[i]);
- printf("Eigenvector %d = ", i);
- for ( j = 0; j <= n-1; ++j ) {
- printf("%12.6f", ev[j][i]);
- }
- printf("\n");
- }
- printf("Count %d\n", count);
- }