Linear Algebra and the C Language/a0i9
Install and compile this file in your working directory.
/* ------------------------------------ */
/* Save as : c00b.c */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
void fun(int r)
{
double **A = rdefinite_positive_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:");
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,P6,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(rp_I(R3)+R2);
} while(stop_w());
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
Let's check that A = V * EValue * VT.
Screen output example:
A:
+57.64 +12.78 +7.50 +0.39 -0.77
+12.78 +80.50 +10.24 -9.83 +4.40
+7.50 +10.24 +60.46 +2.97 -15.95
+0.39 -9.83 +2.97 +61.19 +2.31
-0.77 +4.40 -15.95 +2.31 +48.21
TA = V EValue VT
+57.64 +12.78 +7.50 +0.39 -0.77
+12.78 +80.50 +10.24 -9.83 +4.40
+7.50 +10.24 +60.46 +2.97 -15.95
+0.39 -9.83 +2.97 +61.19 +2.31
-0.77 +4.40 -15.95 +2.31 +48.21
A - TA = 0
-0.000000 +0.000000 -0.000000 -0.000000 +0.000000
+0.000000 -0.000000 -0.000000 -0.000000 +0.000000
-0.000000 -0.000000 +0.000000 +0.000000 +0.000000
-0.000000 -0.000000 +0.000000 +0.000000 +0.000000
+0.000000 +0.000000 +0.000000 +0.000000 -0.000000
Press return to continue
Press X return to stop