## [Example] Solving math linear equations with 4 unknown variables

We’ll put some use of Matrix library for CodeIgniter that we already implemented to solve a linear equation.
Let’s say we have linear equations with 4 unknown variables like this:
$\begin{array}{rcl} 2a+3b+c+6d &=& 4 \\ 4a-2b+0.5c+d &=&2 \\ 6a+b-d&=&-1 \\ 2a+2b-c+3d&=&4 \end{array}$

That linear equation can be written in Matrix notation like this:
$\left[ \begin{matrix} 2&3&1&6\\ 4&-2&0.5&1 \\ 6&1&0&-1\\ 2&2&-1&3 \end{matrix} \right] \left[ \begin{matrix} a\\b\\c\\d \end{matrix} \right] = \left[ \begin{matrix} 4\\2\\-1\\4 \end{matrix} \right]$

And can be solved by this matrix equation:
$\left[ \begin{matrix} a\\b\\c\\d \end{matrix} \right] = \left[ \begin{matrix} 2&3&1&6\\ 4&-2&0.5&1 \\ 6&1&0&-1\\ 2&2&-1&3 \end{matrix} \right]^{-1} \left[ \begin{matrix} 4\\2\\-1\\4 \end{matrix} \right]$

And this is how we solve it on php/CodeIgniter:

Quite simple isn’t it?!

PS.: I’m glad I can use my Latex knowledge in this post 😛