Category : C Source Code
Archive   : CEPHES22.ZIP
Filename : EIGTST.C

 
Output of file : EIGTST.C contained in archive : CEPHES22.ZIP
/* Test program for eigens.c
*/

#define N 11
#define DEBUG 0
static double A[N*N], A0[N*N], X[N*N], D[N*N];
static double RR[N*N];
static double B[N], Y[N];
static int IPS[N];
double maxoffd(), sqrt();

main()
{
long ntrials;
int i, j, k;
double x, e, merr;

merr = 0.0;
ntrials = 0;

loop:

/* Fill A[] with random numbers */
k = N*(N+1)/2;
for( i=0; i {
drand( &x );
x -= 1.5;
x = x + x;
A[i] = x;
}
/* Unpack A into a symmetric matrix A0 */
tritosquare( N, A, A0 );

eigens( A, RR, B, N );
mtransp( N, RR, RR );

#if DEBUG
/* Print the computed eigenvalues */
for( i=0; i printf( "%6.2f", B[i] );
/* Print the reduced triangular matrix */
printf( "\n" );
k = 0;
for( i=0; i {
for( j=0; j<=i; j++ )
{
printf( "%6.2f", A[k] );
k += 1;
}
printf( "\n" );
}

/* Print the original symmetric matrix */
printf( "\n" );
for( i=0; i {
for( j=0; j printf( "%6.2f", A0[N*i+j] );
printf( "\n" );
}

/* Print the matrix of eigenvectors */
printf( "\n" );
for( i=0; i {
for( j=0; j printf( "%6.2f", RR[N*i+j] );
printf( "\n" );
}

#endif

/* Multiply the original matrix by the eigenvectors */
mmmpy( N, N, A0, RR, D );
/* Divide each result vector by the corresponding eigenvalue. */
k = 0;
for( i=0; i {
x = B[i];
for( j=0; j {
D[k] /= x;
k += 1;
}
}

#if DEBUG
printf( "\n" );
for( i=0; i {
for( j=0; j printf( "%6.2f", D[N*i+j] );
printf( "\n" );
}
#endif

/* Compare the result with the computed eigenvector */
mtransp( N, D, D );
e = 0.0;
for( i=0; i {
x = D[i] - RR[i];
if( x < 0 )
x = -x;
if( x > e )
e = x;
}
if( e > merr )
merr = e;
ntrials += 1;
printf( "%4ld %.3e\n", ntrials, merr );
goto loop;
}


  3 Responses to “Category : C Source Code
Archive   : CEPHES22.ZIP
Filename : EIGTST.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/