Linear Algebra and the C Language/a0ih
Install and compile this file in your working directory.
/* ------------------------------------ */
/* Save as : c00b.c */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
void fun(int r)
{
double **A = rdefinite_negative_mR( i_mR(r,r), 99);
double **TA = i_mR(r,r);
double **V = i_mR(r,r);
double **VT = i_mR(r,r);
double **EValue = i_mR(r,r);
double **T1 = i_mR(r,r);
clrscrn();
printf(" A: Definite negative");
p_mR(A,S10,P2,C6);
/* Eigenvector */
eigs_V_mR(A,V);
transpose_mR(V,VT);
/* Eigenvalue = VT A V */
mul_mR(VT,A,T1);
mul_mR(T1,V,EValue);
printf(" TA = V EValue VT");
mul_mR(V,EValue,T1);
mul_mR(T1,VT,TA);
p_mR(TA,S10,P2,C6);
printf(" A - TA = 0");
sub_mR(A,TA,T1);
p_mR(T1,S10,P2,C6);
f_mR(A);
f_mR(TA);
f_mR(V);
f_mR(VT);
f_mR(EValue);
f_mR(T1);
}
/* ------------------------------------ */
int main(void)
{
time_t t;
srand(time(&t));
do
{
fun(RC4);
} while(stop_w());
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
Let's check that A = V * EValue * VT.
Screen output example:
A: Definite negative
-48.38 -22.55 +17.54 +15.82
-22.55 -71.78 -0.14 +2.78
+17.54 -0.14 -20.28 -9.50
+15.82 +2.78 -9.50 -64.56
TA = V EValue VT
-48.38 -22.55 +17.54 +15.82
-22.55 -71.78 -0.14 +2.78
+17.54 -0.14 -20.28 -9.50
+15.82 +2.78 -9.50 -64.56
A - TA = 0
+0.00 +0.00 +0.00 +0.00
+0.00 -0.00 -0.00 +0.00
+0.00 -0.00 -0.00 -0.00
+0.00 +0.00 -0.00 +0.00
Press return to continue
Press X return to stop