Linear Algebra and the C Language/a09j
Install and compile this file in your working directory.
/* ------------------------------------ */
/* Save as: c00e.c */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
# define RAb C4
# define CA C6
# define Cb C1
/* ------------------------------------ */
# define FREEV C3
/* ------------------------------------ */
/* ------------------------------------ */
void X_p_freeV(
double **b, /* b + the free variables */
int e, /* Control the space between the numbers. */
int d) /* Control the number of digits after the point. */
{
int m; /* Index of x */
int r; /* Index for the rows */
int c; /* Index for the columns */
char v; /* Name of the free variables: s, t, u... */
m = 0;
for(r=R1; r<b[R_SIZE][C0]; r++)
{
v = 'y' - (b[R_SIZE][C0]-C1);
printf("\n");
m++;
printf(" x%d = ",m);
for(c=C1; c<b[C_SIZE][C0]; c++)
{
if(c==C1) printf(" %+*.*f",e,d,b[r][c]); /* Print b */
else
{
if(fabs(b[r][c])>ERROR_E) printf(" %+*.*f*%c",e,d,b[r][c],v);
else printf(" %+*.*f*%c",e,d, 0.,v);
v++;
} /* If the coefficient is not zero, display it */
} /* If the coefficient is zero, display 0 */
}
printf("\n");
}
/* ------------------------------------ */
/* ------------------------------------ */
int main(void)
{
double ab[R4*C7]={
+1.0, -3.0, +4.5, -0.5, +4.0, +1.0, +0.0,
-0.0, -0.0, +1.0, +3.0, -2.0, -6.0, -0.0,
+0.0, +0.0, +0.0, +0.0, +1.0, +5.0, +0.0,
+0.0, +0.0, +0.0, +0.0, +0.0, +0.0, +0.0
};
double **Ab = ca_A_mR(ab, i_Abr_Ac_bc_mR(RAb, CA, Cb));
double **Ab_free = i_Abr_Ac_bc_mR(CA, CA, Cb + FREEV);
double **b_free = i_mR(CA, Cb + FREEV);
clrscrn();
printf(" Ab: b");
p_mR(Ab, S6,P1,C10);
printf(" Ab: gj_PP_mR(Ab,NO); b");
gj_PP_mR(Ab,NO);
p_mR(Ab, S6,P1,C10);
stop();
clrscrn();
put_zeroR_mR(Ab,Ab_free);
printf(" Ab_free: put_zeroR_mR();"
" b FREEV");
p_mR(Ab_free, S7,P2,C10);
put_freeV_mR(Ab_free);
printf(" Ab_free: put_freeV_mR(Ab_free);"
" b FREEV");
p_mR(Ab_free, S7,P2,C10);
stop();
clrscrn();
printf(" See above for the function code: p_freeV();\n\n\n\n");
stop();
clrscrn();
gj_PP_mR(Ab_free,YES);
printf(" Ab_free: gj_PP_mR(Ab_free,YES); b FREEV");
p_mR(Ab_free, S6,P1,C10);
c_Ab_b_mR(Ab_free,b_free);
printf(" b FREEV");
p_mR(b_free, S6,P1,C10);
printf(" b_free: b FREEV p_freeV();");
X_p_freeV(b_free, S6,P1);
stop();
f_mR(Ab);
f_mR(Ab_free);
f_mR(b_free);
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
Screen output example:
Ab: b
+1.0 -3.0 +4.5 -0.5 +4.0 +1.0 +0.0
-0.0 -0.0 +1.0 +3.0 -2.0 -6.0 -0.0
+0.0 +0.0 +0.0 +0.0 +1.0 +5.0 +0.0
+0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0
Ab: gj_PP_mR(Ab,NO); b
+1.0 -3.0 +4.5 -0.5 +4.0 +1.0 +0.0
+0.0 -0.0 +1.0 +3.0 -2.0 -6.0 +0.0
+0.0 +0.0 +0.0 +0.0 +1.0 +5.0 +0.0
+0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0
Press return to continue.
Ab_free: put_zeroR_mR(); b FREEV
+1.00 -3.00 +4.50 -0.50 +4.00 +1.00 +0.00 +0.00 +0.00 +0.00
+0.00 +0.00 +0.00 +0.00 +0.00 +0.00 +0.00 +0.00 +0.00 +0.00
+0.00 -0.00 +1.00 +3.00 -2.00 -6.00 +0.00 +0.00 +0.00 +0.00
+0.00 +0.00 +0.00 +0.00 +0.00 +0.00 +0.00 +0.00 +0.00 +0.00
+0.00 +0.00 +0.00 +0.00 +1.00 +5.00 +0.00 +0.00 +0.00 +0.00
+0.00 +0.00 +0.00 +0.00 +0.00 +0.00 +0.00 +0.00 +0.00 +0.00
Ab_free: put_freeV_mR(Ab_free); b FREEV
+1.00 -3.00 +4.50 -0.50 +4.00 +1.00 +0.00 +0.00 +0.00 +0.00
+0.00 +1.00 +0.00 +0.00 +0.00 +0.00 +0.00 +1.00 +0.00 +0.00
+0.00 -0.00 +1.00 +3.00 -2.00 -6.00 +0.00 +0.00 +0.00 +0.00
+0.00 +0.00 +0.00 +1.00 +0.00 +0.00 +0.00 +0.00 +1.00 +0.00
+0.00 +0.00 +0.00 +0.00 +1.00 +5.00 +0.00 +0.00 +0.00 +0.00
+0.00 +0.00 +0.00 +0.00 +0.00 +1.00 +0.00 +0.00 +0.00 +1.00
Press return to continue.
See above for the function code: p_freeV();
Press return to continue.
Ab_free: gj_PP_mR(Ab_free,YES); b FREEV
+1.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +3.0 +14.0 +37.0
+0.0 +1.0 +0.0 +0.0 +0.0 +0.0 +0.0 +1.0 +0.0 +0.0
+0.0 +0.0 +1.0 +0.0 +0.0 +0.0 +0.0 +0.0 -3.0 -4.0
+0.0 +0.0 +0.0 +1.0 +0.0 +0.0 +0.0 +0.0 +1.0 +0.0
+0.0 +0.0 +0.0 +0.0 +1.0 +0.0 +0.0 +0.0 +0.0 -5.0
+0.0 +0.0 +0.0 +0.0 +0.0 +1.0 +0.0 +0.0 +0.0 +1.0
b FREEV
+0.0 +3.0 +14.0 +37.0
+0.0 +1.0 +0.0 +0.0
+0.0 +0.0 -3.0 -4.0
+0.0 +0.0 +1.0 +0.0
+0.0 +0.0 +0.0 -5.0
+0.0 +0.0 +0.0 +1.0
b_free: b FREEV p_freeV();
x1 = +0.0 +3.0*s +14.0*t +37.0*u
x2 = +0.0 +1.0*s +0.0*t +0.0*u
x3 = +0.0 +0.0*s -3.0*t -4.0*u
x4 = +0.0 +0.0*s +1.0*t +0.0*u
x5 = +0.0 +0.0*s +0.0*t -5.0*u
x6 = +0.0 +0.0*s +0.0*t +1.0*u
Press return to continue.