Linear Algebra and the C Language/a0n1
Install and compile this file in your working directory.
/* ------------------------------------ */
/* Save as: c00a.c */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
void fun(int r)
{
double **A = rsymmetric_mR( i_mR(r,r),9);
double **InvA = invgj_mR(A, i_mR(r,r));
double **AEVect = eigs_V_mR(A, i_mR(r,r));
double **InvAEVect = eigs_V_mR(InvA, i_mR(r,r));
clrscrn();
printf(" A:");
p_mR(A, S10,P4,C6);
printf(" InvA:");
p_mR(InvA, S10,P4,C6);
stop();
clrscrn();
printf(" The matrix A and the matrix InvA\n"
" have the same eingvectors. They \n"
" are in reverse order. \n\n\n"
" The eigenvectors of A being \n"
" an orthonormal matrix, we \n"
" will simply take its transpose \n"
" as inverse in the next files. \n\n"
" EigenVector of A:");
p_mR(AEVect,S10,P4,C6);
printf(" EigenVector of InvA:");
p_mR(InvAEVect,S10,P4,C6);
f_mR(A);
f_mR(InvA);
f_mR(AEVect);
f_mR(InvAEVect);
}
/* ------------------------------------ */
int main(void)
{
time_t t;
srand(time(&t));
do
{
fun(R3);
} while(stop_w());
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
To calculate the spectral decomposition of matrix A. We need the eigenvectors and eigenvalues of matrix A and the eigenvectors of the inverse of A. The eigenvectors of A being an orthonormal matrix, we will take its transpose as inverse in the next files.
Screen output example:
A:
-5.0000 +4.0000 -2.0000
+4.0000 +2.0000 -2.0000
-2.0000 -2.0000 +5.0000
InvA:
-0.0698 +0.1860 +0.0465
+0.1860 +0.3372 +0.2093
+0.0465 +0.2093 +0.3023
Press return to continue.
The matrix A and the matrix InvA
have the same eingvectors. They
are in reverse order.
The eigenvectors of A being
an orthonormal matrix, we
will simply take its transpose
as inverse in the next files.
EigenVector of A:
-0.3066 +0.9159 +0.2592
-0.5409 -0.3917 +0.7443
+0.7832 +0.0881 +0.6155
EigenVector of InvA:
+0.2592 +0.9159 -0.3066
+0.7443 -0.3917 -0.5409
+0.6155 +0.0881 +0.7832
Press return to continue
Press X return to stop