Jump to content

Linear Algebra and the C Language/a08e

From Wikibooks, open books for an open world


Install and compile this file in your working directory.

/* ------------------------------------ */ /* Save as : c00a.c */ /* ------------------------------------ */ #include "v_a.h" /* ------------------------------------ */ #define RA R3 #define CA C4 #define Cb C1 /* ------------------------------------ */ /* ------------ Chemistry ------------ */ void p_xn_mR( double **b ) {  int r;  for(r=R1; r<b[R_SIZE][C0]; r++)  printf("double x%d = %+0.8f;\n",r,b[r][C2]);  printf("\n\n"); } /* ------------------------------------ */ /* ------------------------------------ */ int main(void) { double ab[RA*(CA+C1)]={ // x1 x2 x3 x4 b  1, 0, -1, -0, 0, //N  3, 0, -0, -2, 0, //H  0, 2, -1, -1, 0, //O  }; double **Ab = ca_A_mR(ab,i_Abr_Ac_bc_mR(RA,CA,Cb)); double **Ab_free = i_Abr_Ac_bc_mR(csize_A_R(Ab),csize_A_R(Ab),Cb+C1); double **b_free = i_mR(rsize_R(Ab_free),csize_b_R(Ab_free));   clrscrn();  printf(" Ab :");  p_mR(Ab,S10,P4,C10);  printf(" Ab : gj_PP_mR(Ab,NO) :");  gj_PP_mR(Ab,NO);  p_mR(Ab,S10,P4,C10);  put_zeroR_mR(Ab,Ab_free);   printf(" Ab_free : put_zeroR_mR(Ab,Ab_free);");   p_mR(Ab_free,S10,P4,C10);     put_freeV_mR(Ab_free);  printf(" Ab_free : put_freeV_mR(Ab_free);");   p_mR(Ab_free,S10,P4,C10);   stop();    clrscrn();   printf(" Ab_free : gj_PP_mR(Ab_free,YES);");  gj_PP_mR(Ab_free,YES);   p_mR(Ab_free,S10,P4,C10);   c_Ab_b_mR(Ab_free,b_free);    printf(" b_free : free variables");  p_freeV(b_free,S8,P8);  printf("Copy/Paste These code in the c00b.c file.\n\n");  p_xn_mR(b_free);  stop();  f_mR(Ab);  f_mR(Ab_free);  f_mR(b_free);    return 0; } /* ------------------------------------ */ /* ------------------------------------ */ 
  • The values ​​for calculating the coefficients of the chemical equation are given in a list.
  • You need to copy the list of these values ​​into the following file: c00b.c.

Screen output example:

 Ab :  +1.0000 +0.0000 -1.0000 +0.0000 +0.0000   +3.0000 +0.0000 +0.0000 -2.0000 +0.0000   +0.0000 +2.0000 -1.0000 -1.0000 +0.0000   Ab : gj_PP_mR(Ab,NO) :  +1.0000 +0.0000 +0.0000 -0.6667 +0.0000   +0.0000 +1.0000 -0.5000 -0.5000 +0.0000   -0.0000 -0.0000 +1.0000 -0.6667 -0.0000   Ab_free : put_zeroR_mR(Ab,Ab_free);  +1.0000 +0.0000 +0.0000 -0.6667 +0.0000 +0.0000   +0.0000 +1.0000 -0.5000 -0.5000 +0.0000 +0.0000   -0.0000 -0.0000 +1.0000 -0.6667 -0.0000 +0.0000   +0.0000 +0.0000 +0.0000 +0.0000 +0.0000 +0.0000   Ab_free : put_freeV_mR(Ab_free);  +1.0000 +0.0000 +0.0000 -0.6667 +0.0000 +0.0000   +0.0000 +1.0000 -0.5000 -0.5000 +0.0000 +0.0000   -0.0000 -0.0000 +1.0000 -0.6667 -0.0000 +0.0000   +0.0000 +0.0000 +0.0000 +1.0000 +0.0000 +1.0000   Press return to continue.   Ab_free : gj_PP_mR(Ab_free,YES);  +1.0000 +0.0000 +0.0000 +0.0000 +0.0000 +0.6667   +0.0000 +1.0000 +0.0000 +0.0000 +0.0000 +0.8333   +0.0000 +0.0000 +1.0000 +0.0000 +0.0000 +0.6667   +0.0000 +0.0000 +0.0000 +1.0000 +0.0000 +1.0000   b_free : free variables  x1 = +0.00000000 +0.66666667*u  x2 = +0.00000000 +0.83333333*u  x3 = +0.00000000 +0.66666667*u  x4 = +0.00000000 +1.00000000*u Copy/Paste These code in the c00b.c file. double x1 = +0.66666667; double x2 = +0.83333333; double x3 = +0.66666667; double x4 = +1.00000000;  Press return to continue.