Linear Algebra and the C Language/a0ig
Install and compile this file in your working directory.
/* ------------------------------------ */
/* Save as : c00a.c */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
void fun(int r)
{
double **A = rdefinite_negative_mR( i_mR(r,r), 99);
double **invA = inv_mR(A, i_mR(r,r));
double **sA = smul_mR(-1,A, i_mR(r,r));
double **EValue = eigs_mR(A, i_mR(r,C1));
clrscrn();
printf(" A: Definite negative");
p_mR(A,S12,P6,C6);
printf(" invA:");
p_mR(invA,S12,P6,C6);
printf(" eigs_mR(A,EValue);");
p_mR(EValue,S9,P3,C1);
stop();
clrscrn();
printf(" (-)A: Definite positive");
p_mR(sA,S12,P6,C6);
printf(" Eigenvalues: eigs_mR(-A,EValue); ");
eigs_mR(sA,EValue);
p_mR(EValue,S9,P3,C1);
f_mR(A);
f_mR(sA);
f_mR(invA);
f_mR(EValue);
}
/* ------------------------------------ */
int main(void)
{
time_t t;
srand(time(&t));
do
{
fun(RC4);
} while(stop_w());
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
The eigenvalues of a negative-definite matrix are negative. The matrix is invertible. -A is a positive-definite matrix
Screen output example:
A: Definite negative
-38.159304 -11.644166 -12.362260 +16.673860
-11.644166 -30.691904 +7.740817 +12.324434
-12.362260 +7.740817 -53.377996 +2.602676
+16.673860 +12.324434 +2.602676 -37.770795
invA:
-0.038618 +0.012241 +0.010116 -0.012357
+0.012241 -0.043432 -0.009593 -0.009429
+0.010116 -0.009593 -0.022479 -0.000213
-0.012357 -0.009429 -0.000213 -0.035022
eigs_mR(A,EValue);
-67.000
-55.000
-21.000
-17.000
Press return to continue.
(-)A: Definite positive
+38.159304 +11.644166 +12.362260 -16.673860
+11.644166 +30.691904 -7.740817 -12.324434
+12.362260 -7.740817 +53.377996 -2.602676
-16.673860 -12.324434 -2.602676 +37.770795
Eigenvalues: eigs_mR(-A,EValue);
+67.000
+55.000
+21.000
+17.000
Press return to continue
Press X return to stop