Linear Algebra and the C Language/a0mr
Install and compile this file in your working directory.
/* ------------------------------------ */
/* Save as : c00d.c */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
#define RA R4
#define CA C4
#define RX R4
#define CX C1
/* ------------------------------------ */
/* ------------------------------------ */
int main(void)
{
double a[RA*CA]={
+3, -4, -2, -1,
+5, -3, -0, -2,
+6, -0, -3, -2,
+3, -3, -1, -3
};
double x_B[RX*CX]={
+1,
+2,
+3,
+4
};
double b[RA*CA]={
+1, +2, +6, +6,
+3, +2, +1, +6,
+5, +5, +3, +6,
+5, +5, +2, +4,
};
double **A = ca_A_mR(a, i_mR(RA,CA));
double **B = ca_A_mR(b, i_mR(RA,CA));
double **x_b = ca_A_mR(x_B, i_mR(RX,CX));
double **x_s = mul_mR(B,x_b, i_mR(RX,CX));
double **T = i_mR(RA,CX) ;
double **invB = inv_mR(B, i_mR(RA,CA));
double **invBA = mul_mR(invB,A, i_mR(RA,CA));
double **D = mul_mR(invBA,B, i_mR(RA,CA));
double **Dx_b = mul_mR(D,x_b, i_mR(RA,CX));
clrscrn();
printf(" In the Standard basis the linear application is:\n\n"
" With A :");
p_mR(A,S6,P2,C7);
printf(" And x_s:");
p_mR(x_s,S6,P2,C7);
printf(" T(x_s) = A x_s");
p_mR(mul_mR(A,x_s,T),S8,P2,C7);
stop();
clrscrn();
printf(" In the \"B\" basis the linear application is: \n\n"
" With D: (InvB A B)");
p_mR(D,S7,P2,C7);
printf(" And x_b:");
p_mR(x_b,S7,P2,C7);
printf(" [T(x_b)]_b = D x_b");
p_mR(mul_mR(D,x_b,Dx_b),S8,P2,C7);
stop();
clrscrn();
printf(" A \n"
" x_s -----------> T(x_s) \n"
" ^ ^ \n"
" | | \n"
" B | | B \n"
" | D | \n"
" x_b -----------> [T(x_b)]_b\n\n"
" Verify if: B [T(x_b)]_b = T(x_s)\n\n");
printf(" B [T(x_b)]_b:");
p_mR(mul_mR(B,Dx_b,T),S8,P2,C7);
printf(" T(x_s):");
p_mR(mul_mR(A,x_s,T),S8,P2,C7);
stop();
f_mR(A);
f_mR(B);
f_mR(D);
f_mR(x_b);
f_mR(x_s);
f_mR(T);
f_mR(invB);
f_mR(invBA);
f_mR(Dx_b);
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
Screen output example:
In the Standard basis the linear application is:
With A :
+3.00 -4.00 -2.00 -1.00
+5.00 -3.00 +0.00 -2.00
+6.00 +0.00 -3.00 -2.00
+3.00 -3.00 -1.00 -3.00
And x_s:
+47.00
+34.00
+48.00
+37.00
T(x_s) = A x_s
-128.00
+59.00
+64.00
-120.00
Press return to continue.
In the "B" basis the linear application is:
With D: (InvB A B)
-115.00 -89.00 -118.00 -304.00
+107.00 +82.20 +112.40 +289.20
-48.00 -37.80 -50.60 -126.80
+27.50 +22.40 +33.80 +77.40
And x_b:
+1.00
+2.00
+3.00
+4.00
[T(x_b)]_b = D x_b
-1863.00
+1765.40
-782.60
+483.30
Press return to continue.
A
x_s -----------> T(x_s)
^ ^
| |
B | | B
| D |
x_b -----------> [T(x_b)]_b
Verify if: B [T(x_b)]_b = T(x_s)
B [T(x_b)]_b:
-128.00
+59.00
+64.00
-120.00
T(x_s):
-128.00
+59.00
+64.00
-120.00
Press return to continue.