Easiest way to solve system of linear equations involving singular matrix 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.
 A: 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.
A: As I said in my comment, you want to find the nullspace of the matrix.
A singular matrix will not have an inverse, by definition. So you will never find $C^{-1}$, because it does not exist!
Assuming your calculation is correct, from the row reduced form, you have the equivalent of the set of linear equations
$$\begin{align}
x_1+x_5&=0\\
x_2+2x_5&=0\\
x_3+2x_5&=0\\
x_4+x_5&=0.
\end{align}$$
What you have is $x_5$ is a free variable, which means it can take any value.
From above, it should be clear that the solution is
$$x=\begin{bmatrix}-x_5\\-2x_5\\-2x_5\\-x_5\\x_5\end{bmatrix}=-x_5\begin{bmatrix}1\\2\\2\\1\\-1\end{bmatrix}.$$
So, any solution of your linear system will be a multiple of $[1,2,2,1,-1]^T$. This vector forms a basis for the nullspace of the matrix.
Retturning to your application, the balance equation is
$$
Na_2CO_3(s)+2HCl(aq)\to 2NaCl(aq)+CO_2(g)-H_2O(l).
$$
The idea of the multiple comes in because doubling the quantity of chemicals on the left side will also scale the quantity on the right side.
