[Math] Easiest way to solve system of linear equations involving singular matrix

chemistrylinear algebrasystems of equations

I am trying to balance an unbalanced chemical equation by using setting up a system of linear equations to solve for the stoichiometric coefficients in the chemical equation. After setting up a matrix, to try and solve the system, I can't because one of the matrices is a singular array.

I have taken a look at the answer at Solving systems of linear equations when matrix of coefficients is singular, but it seems like some of the answers say a system where you have a singular matrix can't be solved, while others allude to other methods. I have a very basic understanding of linear algebra, so I can't figure out how to apply some of the methods mentioned in the above question, but would like to learn how to solve systems where the singular matrix arises, since I'm sure ill come across them more than this once. My question is basically identical to Is it possible to balance a chemical equation without using trial and error?, but would like to know how to solve using the matrix method.

Here is the unbalanced chemical equation, I need to make it balanced meaning the number of atoms/molecules on each side of the $\to$ symbol is equal to the other side, e.g. there are $2\times\mathrm{Na}$ atoms of left side, only $1\times\mathrm{Na}$ on right hand side. The subscripts cant be changed, so you balance by putting a stoichiometric coefficient in front of each item, $x\mathrm{Na}$, $2\mathrm{Na}$:

$$\mathrm{Na_2CO_3(s) + HCl(aq) \to NaCl(aq) + CO_2(g) + H_2O(l)}$$

Adding stoichiometric coefficients:

$$a\mathrm{Na_2CO_3(s)} + b\mathrm{HCl(aq)} \to c\mathrm{NaCl(aq)} + d\mathrm{CO_2(g)} + e\mathrm{H_2O(l)}$$

Setting up system of linear equations:

$$
\begin{align}
\mathrm{Na}&: &2a+0b-1c-0d&=0e\\
\mathrm{C}&: &1a+0b-0c-1d&=0e\\
\mathrm{O}&: &3a+0b-0c-2d&=-1e\\
\mathrm{H}&: &0a+1b-0c-0d&=-2e\\
\mathrm{Cl}&: &0a+1b-1c-0d&=0e
\end{align}
$$

Since I need to have a square matrix, I move the right hand side over to the left and get:

$$
A=
\begin{bmatrix}
2&0&-1&0&0&\\
1&0&0&-1&0&\\
3&0&0&-2&1&\\
0&1&0&0&2&\\
0&1&-1&0&0&\\
\end{bmatrix}
$$

and

$$
B=
\begin{bmatrix}
0&0&0&0&0&\\
\end{bmatrix}
$$

then try to solve $A^{-1}\times \det (A)\times B=$$\begin{bmatrix} a&b&c&d&e&\\\end{bmatrix}$, but then my calculator gives me a singular array error message.

Best Answer

Note that the setup should be as follows:

$$ \begin{align} \mathrm{Na}&: &2a+0b-1c-0d-0e&=0\\ \mathrm{C}&: &1a+0b-0c-1d-0e&=0\\ \mathrm{O}&: &3a+0b-0c-2d-1e&=0\\ \mathrm{H}&: &0a+1b-0c-0d-2e&=0\\ \mathrm{Cl}&: &0a+1b-1c-0d-0e&=0 \end{align} $$

and I get: $$ A= \begin{bmatrix} 2&0&-1&0&0&\\ 1&0&0&-1&0&\\ 3&0&0&-2&-1&\\ 0&1&0&0&-2&\\ 0&1&-1&0&0&\\ \end{bmatrix} $$

Now the coefficients $a$, $b$, $c$, $d$ and $e$ all come out positive.