Linear Algebra and the C Language/a08a


Balancing a chemical equation


a) The system:

double ab[RA*(CA+C1)]={
//  x1   x2   x3   x4      b
    
    +0,  +0,  -0,  -0,     0, //C
    +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

    +3,  +0,  -0,  -0,     0, //C
    +8,  +0,  -0,  -0,     0, //H
    +0,  +0,  -0,  -0,     0, //O      
};
  • x1 is related to two atoms C and H.
  • There is three C that we write in the first column of the first row.
  • There are eight 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

    +3,  +0,  -0,  -0,     0, //C
    +8,  +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

    +3,  +0,  -1,  -0,     0, //C
    +8,  +0,  -0,  -2,     0, //H
    +0,  +2,  -2,  -1,     0, //O             
};

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