Linear Algebra and the C Language/a0kq
Appearance
Install and compile this file in your working directory.
/* ------------------------------------ */ /* Save as: c00f.c */ /* ------------------------------------ */ #include "v_a.h" /* ------------------------------------ */ /* ------------------------------------ */ double **X_sort_c_mR( double **Ab ) { double **T = i_RC_mR(Ab[R_SIZE][C0],Ab[C_SIZE][C0]); int c; for(c=C1; c<Ab[C_SIZE][C0]; c++) c_c_withR0_mR(Ab, c, /* Copy the columns of Ab into */ T, Ab[R0][c]); /* T in the good order */ c_withR0_mR(T,Ab); /* Copy T into Ab */ f_mR(T); return(Ab); } /* ------------------------------------ */ /* ------------------------------------ */ double **X_invgj_mR( double **A, double **invA ) { double **ID = i_RC_mR(A[R_SIZE][C0],A[C_SIZE][C0]); double **AID; int r = A[R_SIZE][C0]; r--; AID = i_Abr_Ac_bc_mR(r,r,r); eye_mR(ID); c_A_b_Ab_mR(A,ID,AID); invgj_pivot_mR(AID); printf(" AID: Before sort_c_mR();\n"); pall_mR(AID, S8,P4,C7); X_sort_c_mR(AID); printf(" See above for the function code: sort_c_mR();\n" " The rows are not sorted:\n\n\n\n AID: After sort_c_mR();\n"); pall_mR(AID, S8,P4,C7); /* sort_r_mR(AID); */ /* c_Inv_A_mR(AID,invA); */ f_mR(AID); f_mR(ID); return(invA); } /* ------------------------------------ */ /* ------------------------------------ */ void fun(int r) { double **A = rE_mR( i_mR(r,r), 999.,1E-3); double **InvA = i_mR(r,r); clrscrn(); X_invgj_mR(A,InvA); f_mR(A); f_mR(InvA); } /* ------------------------------------ */ int main(void) { time_t t; srand(time(&t)); do { fun(C3); } while(stop_w()); return 0; } /* ------------------------------------ */ /* ------------------------------------ */ Screen output example:
AID: Before sort_c_mR(); +4 +1 +3 +2 +4 +6 +5 +7 +1.0000 +0.0000 +0.0000 +0.3783 +0.2513 +5.4544 +4 +0.0000 +1.0000 +0.0000 -0.5338 +0.9207 +2.5858 +0 -0.0000 -0.0000 +1.0000 +0.3948 +0.2888 -4.5107 See above for the function code: sort_c_mR(); The rows are not sorted: AID: After sort_c_mR(); +4 +1 +2 +3 +4 +5 +6 +7 +1.0000 +0.0000 +0.0000 +0.3783 +5.4544 +0.2513 +4 +0.0000 +0.0000 +1.0000 -0.5338 +2.5858 +0.9207 +0 -0.0000 +1.0000 -0.0000 +0.3948 -4.5107 +0.2888 Press return to continue Press X return to stop