Linear Algebra and the C Language/a0gl
Install and compile this file in your working directory.
/* ------------------------------------ */
/* Save as : c00e.c */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
#define ARRAY A2
#define RCA R5
/* ------------------------------------ */
void fun(void)
{
double **A[ARRAY];
double **InvA[ARRAY];
double **P = r_mR( i_mR(RCA,RCA),99);
double **InvP = inv_mR(P, i_mR(RCA,RCA) );
double **T = i_mR(RCA,RCA);
double **InvP_InvA0_P = i_mR(RCA,RCA);
int i;
for(i=A0; i<ARRAY; i++)
{
A[i] = i_mR(RCA,RCA);
InvA[i] = i_mR(RCA,RCA);
}
rsymmetric_mR(A[R0],99);
mul_mR(InvP,A[A0],T);
mul_mR(T,P,A[A0+A1]);
clrscrn();
printf(" The two similar matrices :\n\n"
" A[%d] = InvP A[%d] P \n\n",A1,A0);
for(i=A0; i<ARRAY; i++)
{
printf(" A[%d] : ",i);
p_mR(A[i], S12,P4,C6);
}
stop();
clrscrn();
for(i=A0; i<ARRAY; i++)
{
inv_mR(A[i],InvA[i]);
}
mul_mR(InvP,InvA[A0],T);
mul_mR(T,P,InvP_InvA0_P);
printf(" If A[%d] = InvP A[%d] P Then "
" InVA[%d] = InvP InVA[%d] P \n\n",A1,A0 ,A1,A0);
printf(" InVA[%d] : ",A1);
pE_mR(InvA[1], S12,P4,C6);
printf(" InvP InVA[%d] P : ",A0);
pE_mR(InvP_InvA0_P, S12,P4,C6);
for(i=A0; i<ARRAY; i++)
{
f_mR(A[i]);
f_mR(InvA[i]);
}
f_mR(P);
f_mR(InvP);
f_mR(T);
f_mR(InvP_InvA0_P);
}
/* ------------------------------------ */
int main(void)
{
time_t t;
srand(time(&t));
do{
fun();
}while(stop_w());
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
Screen output example:
The two similar matrices :
A[1] = InvP A[0] P
A[0] :
+82.0000 +65.0000 +86.0000 -99.0000 +15.0000
+65.0000 -75.0000 -85.0000 -42.0000 -22.0000
+86.0000 -85.0000 -1.0000 +75.0000 +8.0000
-99.0000 -42.0000 +75.0000 +31.0000 -97.0000
+15.0000 -22.0000 +8.0000 -97.0000 -40.0000
A[1] :
+5.4781 +82.9444 -180.5620 +212.9966 +218.8392
+230.4664 -359.8709 -788.2735 +917.4393 +239.7937
+55.2520 -231.7830 -58.2085 +50.3652 -178.5631
+234.1154 -518.1748 -458.9903 +584.3454 -141.5204
-200.7368 +430.8753 +760.6541 -949.9923 -174.7442
Press return to continue.
If A[1] = InvP A[0] P Then InVA[1] = InvP InVA[0] P
InVA[1] :
+2.0339e-02 +4.3383e-04 -3.8811e-03 +1.7726e-02 +1.5677e-02
-1.4125e-01 +4.3604e-02 -7.0015e-02 -3.6664e-02 -1.5825e-02
+7.1233e-02 -3.2594e-02 +1.6698e-02 +2.9501e-02 +3.5259e-03
-3.9873e-02 +1.9200e-03 -3.0451e-02 -4.5130e-03 -1.2529e-02
+1.5518e-01 -4.5299e-02 +7.0049e-02 +4.2186e-02 +2.0709e-02
InvP InVA[0] P :
+2.0339e-02 +4.3383e-04 -3.8811e-03 +1.7726e-02 +1.5677e-02
-1.4125e-01 +4.3604e-02 -7.0015e-02 -3.6664e-02 -1.5825e-02
+7.1233e-02 -3.2594e-02 +1.6698e-02 +2.9501e-02 +3.5259e-03
-3.9873e-02 +1.9200e-03 -3.0451e-02 -4.5130e-03 -1.2529e-02
+1.5518e-01 -4.5299e-02 +7.0049e-02 +4.2186e-02 +2.0709e-02
Press return to continue
Press X return to stop