Linear Algebra and the C Language/a0kf
Install and compile this file in your working directory.
/* ------------------------------------ */
/* Save as : c00d.c */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
double **X_sort_r_mR(
double **Ab
)
{
double pivot;
int c;
int r;
int r_pivot = R1;
for ( c=C1; c<Ab[C_SIZE_A][C0]; c++) /* From the first row */
{ /* to the last */
r = r_pivot;
pivot = 0.;
while( (pivot<ERROR_E) && r<Ab[R_SIZE][C0] )
{
pivot = fabs( Ab[r][c] );
if(pivot>ERROR_E) /* If the pivot is not zero */
{ /* swap the row */
swapR_mR(Ab, r, r_pivot);
r_pivot++;
}
r++;
}
}
return(Ab);
}
/* ------------------------------------ */
/* ------------------------------------ */
double **X_gj_TP_mR(
double **Ab
)
{
gj1_T_mR(Ab);
sort_c_mR(Ab);
X_sort_r_mR(Ab);
return(Ab);
}
/* ------------------------------------ */
/* ------------------------------------ */
void fun(int r)
{
double **A = r_mR( i_mR(r,r ),999.);
double **b = r_mR( i_mR(r,C1),999.);
double **Ab = c_A_b_Ab_mR(A,b, i_Abr_Ac_bc_mR(r, r, C1));
/* i_Abr_Ac_bc_mR(RAb, CA, Cb)); */
clrscrn();
printf(" Copy/Paste into the octave window.\n\n");
p_Octave_mR(Ab,"Ab",P0);
printf("\n rref(Ab,.00000000001)\n\n");
stop();
clrscrn();
X_gj_TP_mR(Ab);
printf(" See above for the function code: sort_r_mR(Ab);\n\n"
" gj_TP_mR(Ab);");
p_mR(Ab, S10,P4,C7);
f_mR(Ab);
f_mR(b);
f_mR(A);
}
/* ------------------------------------ */
int main(void)
{
time_t t;
srand(time(&t));
do
{
fun(RC5);
} while(stop_w());
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
Screen output example:
Copy/Paste into the octave window.
Ab=[
+18,-454,-82,-723,-727,+810;
-329,-466,+990,-443,-449,-915;
+860,+841,-459,+102,-176,-480;
+538,+457,+572,+621,-780,-358;
-268,-76,+79,+249,+484,+660]
rref(Ab,.00000000001)
Press return to continue.
See above for the function code: sort_r_mR(Ab);
gj_TP_mR(Ab);
+1.0000 +0.0000 +0.0000 +0.0000 +0.0000 +19.0384
+0.0000 +1.0000 +0.0000 +0.0000 +0.0000 -18.1261
+0.0000 +0.0000 +1.0000 +0.0000 +0.0000 +1.6174
+0.0000 +0.0000 +0.0000 +1.0000 +0.0000 +3.5393
+0.0000 +0.0000 +0.0000 +0.0000 +1.0000 +6.9744
Press return to continue
Press X return to stop