Linear Algebra and the C Language/a09g
Install and compile this file in your working directory.
/* ------------------------------------ */
/* ------------------------------------ */
/* Save as : c00a.c */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
void fun(int r, int c)
{
double **A = i_mR(r,c);
double **b = i_mR(r,C1);
double **Ab = i_Abr_Ac_bc_mR(r,c,C1);
double **new_Ab = i_Abr_Ac_bc_mR(csize_A_R(Ab),
csize_A_R(Ab),
csize_R(A)-rsize_R(A) + C1);
double **x = i_mR(rsize_R(new_Ab),csize_b_R(new_Ab));
double **Ax = i_mR(r,csize_b_R(new_Ab));
r_mR(A,999.);
r_mR(b,999.);
clrscrn();
printf(" A :");
p_mR(A,S8,P0,C7);
printf(" b :");
p_mR(b,S8,P0,C7);
printf(" Ab :");
c_A_b_Ab_mR(A,b,Ab);
p_mR(Ab,S8,P0,C7);
stop();
clrscrn();
GJ_TP_mR(Ab);
printf(" Ab :");
p_mR(Ab,S10,P4,C7);
stop();
clrscrn();
GJ_TPfreeV_mR(Ab,new_Ab);
printf(" new_Ab :");
p_mR(new_Ab,S10,P4,C7);
stop();
clrscrn();
c_Ab_b_mR(new_Ab,x);
printf(" x : b");
p_mR(x,S10,P4,C7);
printf(" x : b + free variables");
p_freeV(x,S8,P4);
stop();
clrscrn();
printf(" b :");
p_mR(b,S8,P0,C7);
printf(" A * x = b :");
mul_mR(A,x,Ax);
p_mR(Ax,S10,P4,C7);
f_mR(new_Ab);
f_mR(Ab);
f_mR(b);
f_mR(A);
f_mR(x);
f_mR(Ax);
}
/* ------------------------------------ */
int main(void)
{
time_t t;
srand(time(&t));
do
{
fun(rp_I(R3)+R1, rp_I(R3)+R4);
} while(stop_w());
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
Screen output example:
A :
+105 +215 -991 -261 +198 +18 +228
-190 -870 +696 -637 -680 -120 -245
b :
+355
+626
Ab :
+105 +215 -991 -261 +198 +18 +228
-190 -870 +696 -637 -680 -120 -245
+355
+626
Press return to continue.
Ab :
+1.0000 +0.0000 -14.1095 -7.2084 +0.5160 -0.2008 +2.8849
+0.0000 +1.0000 +2.2814 +2.3064 +0.6689 +0.1818 -0.3484
+8.7810
-2.6372
Press return to continue.
new_Ab :
+1.0000 +0.0000 +0.0000 +0.0000 +0.0000 +0.0000 +0.0000
+0.0000 +1.0000 +0.0000 +0.0000 +0.0000 +0.0000 +0.0000
+0.0000 +0.0000 +1.0000 +0.0000 +0.0000 +0.0000 +0.0000
+0.0000 +0.0000 +0.0000 +1.0000 +0.0000 +0.0000 +0.0000
+0.0000 +0.0000 +0.0000 +0.0000 +1.0000 +0.0000 +0.0000
+0.0000 +0.0000 +0.0000 +0.0000 +0.0000 +1.0000 +0.0000
+0.0000 +0.0000 +0.0000 +0.0000 +0.0000 +0.0000 +1.0000
+8.7810 +14.1095 +7.2084 -0.5160 +0.2008 -2.8849
-2.6372 -2.2814 -2.3064 -0.6689 -0.1818 +0.3484
+0.0000 +1.0000 +0.0000 +0.0000 +0.0000 +0.0000
+0.0000 +0.0000 +1.0000 +0.0000 +0.0000 +0.0000
+0.0000 +0.0000 +0.0000 +1.0000 +0.0000 +0.0000
+0.0000 +0.0000 +0.0000 +0.0000 +1.0000 +0.0000
+0.0000 +0.0000 +0.0000 +0.0000 +0.0000 +1.0000
Press return to continue.
x : b...
+8.7810 +14.1095 +7.2084 -0.5160 +0.2008 -2.8849
-2.6372 -2.2814 -2.3064 -0.6689 -0.1818 +0.3484
+0.0000 +1.0000 +0.0000 +0.0000 +0.0000 +0.0000
+0.0000 +0.0000 +1.0000 +0.0000 +0.0000 +0.0000
+0.0000 +0.0000 +0.0000 +1.0000 +0.0000 +0.0000
+0.0000 +0.0000 +0.0000 +0.0000 +1.0000 +0.0000
+0.0000 +0.0000 +0.0000 +0.0000 +0.0000 +1.0000
x : b + free variables
x1 = +8.7810 +14.1095*r +7.2084*s -0.5160*t +0.2008*u -2.8849*v
x2 = -2.6372 -2.2814*r -2.3064*s -0.6689*t -0.1818*u +0.3484*v
x3 = +0.0000 +1.0000*r +0.0000*s +0.0000*t +0.0000*u +0.0000*v
x4 = +0.0000 +0.0000*r +1.0000*s +0.0000*t +0.0000*u +0.0000*v
x5 = +0.0000 +0.0000*r +0.0000*s +1.0000*t +0.0000*u +0.0000*v
x6 = +0.0000 +0.0000*r +0.0000*s +0.0000*t +1.0000*u +0.0000*v
x7 = +0.0000 +0.0000*r +0.0000*s +0.0000*t +0.0000*u +1.0000*v
Press return to continue.
b :
+355
+626
A * x = b :
+355.0000 +0.0000 +0.0000 +0.0000 +0.0000 -0.0000
+626.0000 +0.0000 -0.0000 +0.0000 -0.0000 +0.0000
Press return to continue
Press X return to stop