Linear Algebra and the C Language/a08d


Balancing a chemical equation


a) The system:

double ab[RA*(CA+C1)]={
//  x1   x2   x3   x4      b
    
    +0,  +0,  -0,  -0,     0, //N
    +0,  +0,  -0,  -0,     0, //H
    +0,  +0,  -0,  -0,     0, //O      
};


  • Each coefficient must have a column. Here four coefficients therefore four columns.
  • Each atom must have a row. Here, three atoms, so three rows.
  • The coefficients on the left side of the chemical equation must have a positive coefficient. (x1, x2)
  • The coefficients on the right side of the chemical equation must have a negative coefficient. (x3, x4)


b) The first column:

double ab[RA*(CA+C1)]={
//  x1   x2   x3   x4      b

    +1,  +0,  -0,  -0,     0, //N
    +3,  +0,  -0,  -0,     0, //H
    +0,  +0,  -0,  -0,     0, //O      
};
  • x1 is related to two atoms N and H.
  • There is one N that we write in the first column of the first row.
  • There are three H that we write in the first column of the second row.


c) The second column:

double ab[RA*(CA+C1)]={
//  x1   x2   x3   x4      b

    +1,  +0,  -0,  -0,     0, //N
    +3,  +0,  -0,  -0,     0, //H
    +0,  +2,  -0,  -0,     0, //O       
};
  • x2 is related to one atome O.
  • There are two O that we write in the second column of the third row.


d) The third and the fourth columns: (With negative coefficients)

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              
};

Now we need to introduce this system into the file: c00a.c.