Linear Algebra and the C Language/a03o
Install and compile this file in your working directory.
/* ------------------------------------ */
/* Save as: c01d.c */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
#define RA R5
#define CA C3
/* ------------------------------------ */
#define FACTOR_E +1.E-0
/* ------------------------------------ */
void fun(void)
{
double **A = r_mR( i_mR(RA,CA),9);
double **Pinv = Pinv_Rn_mR(A, i_mR(CA,RA),FACTOR_E);
double **APinv = mul_mR(A,Pinv, i_mR(RA,RA));
double **APinvA = mul_mR(APinv,A, i_mR(RA,CA));
clrscrn();
printf(" A:");
p_mR(A, S7,P2,C7);
printf(" Pinv = V invS_T U_T ");
pE_mR(Pinv, S12,P4,C10);
stop();
clrscrn();
printf(" A Pinv:");
p_mR(APinv, S7,P2,C10);
printf(" A Pinv A:");
p_mR(APinvA, S7,P2,C10);
printf(" A:");
p_mR(A, S7,P2,C7);
f_mR(A);
f_mR(Pinv);
f_mR(APinv);
f_mR(APinvA);
}
/* ------------------------------------ */
int main(void)
{
time_t t;
srand(time(&t));
do
{
fun();
} while(stop_w());
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
Screen output example:
A :
-1.00 -1.00 +4.00
+6.00 -6.00 -4.00
+5.00 +7.00 +7.00
+3.00 +8.00 +6.00
+9.00 -4.00 -9.00
Pinv = V * invS_T * U_T
+2.4283e-02 +5.8545e-02 +5.1330e-02 +2.1567e-02 +3.9074e-02
-1.0153e-01 -9.9219e-02 -2.9973e-04 +5.6291e-02 +3.6268e-02
+1.0552e-01 +7.3025e-02 +5.0103e-02 -7.0949e-03 -6.2428e-02
Press return to continue.
A*Pinv :
+0.50 +0.33 +0.15 -0.11 -0.33
+0.33 +0.65 +0.11 -0.18 +0.27
+0.15 +0.11 +0.61 +0.45 +0.01
-0.11 -0.18 +0.45 +0.47 +0.03
-0.33 +0.27 +0.01 +0.03 +0.77
A*Pinv*A :
-1.00 -1.00 +4.00
+6.00 -6.00 -4.00
+5.00 +7.00 +7.00
+3.00 +8.00 +6.00
+9.00 -4.00 -9.00
A :
-1.00 -1.00 +4.00
+6.00 -6.00 -4.00
+5.00 +7.00 +7.00
+3.00 +8.00 +6.00
+9.00 -4.00 -9.00
Press return to continue
Press X return to stop