# 14.2.3.2: System of equations and Matrices

$$\newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} }$$ $$\newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}}$$$$\newcommand{\id}{\mathrm{id}}$$ $$\newcommand{\Span}{\mathrm{span}}$$ $$\newcommand{\kernel}{\mathrm{null}\,}$$ $$\newcommand{\range}{\mathrm{range}\,}$$ $$\newcommand{\RealPart}{\mathrm{Re}}$$ $$\newcommand{\ImaginaryPart}{\mathrm{Im}}$$ $$\newcommand{\Argument}{\mathrm{Arg}}$$ $$\newcommand{\norm}[1]{\| #1 \|}$$ $$\newcommand{\inner}[2]{\langle #1, #2 \rangle}$$ $$\newcommand{\Span}{\mathrm{span}}$$ $$\newcommand{\id}{\mathrm{id}}$$ $$\newcommand{\Span}{\mathrm{span}}$$ $$\newcommand{\kernel}{\mathrm{null}\,}$$ $$\newcommand{\range}{\mathrm{range}\,}$$ $$\newcommand{\RealPart}{\mathrm{Re}}$$ $$\newcommand{\ImaginaryPart}{\mathrm{Im}}$$ $$\newcommand{\Argument}{\mathrm{Arg}}$$ $$\newcommand{\norm}[1]{\| #1 \|}$$ $$\newcommand{\inner}[2]{\langle #1, #2 \rangle}$$ $$\newcommand{\Span}{\mathrm{span}}$$

## System of Equations

To solve a system of equations there are a number of methods that you have already learned in previous classes. Let us look at an example system of equations (two variables; two equations).

$3x + 4y=7$

$-2x+2y=2$

¬ What are three of the four methods to solve this system of equations that you are aware of presently?
• Substitution method
• Take one of the equations and rearrange it so you have either x = ... or y = ... and plug it into the other equation
• This method gets much harder for three or more equations
• Multiply the equations by a coefficient that will allow you to subtract the equations from each other and zero out one of the variables
• This method gets harder for three or more equations
• Graphical method
• This is where you graph the functions and determine the answer from the intersection
• For three equation you would need a to plot in 3D which is already difficult because we don't really plot 3D (plot 3D on 2D is what we do), for more than three you would have to go into hyper dimensions
• This method is not practical for multiple equations though it is instructive

The better method for three or more equations would be a matrix method (the fourth method). As an example we will solve the simple of system of equations in octave.

A = [3 4;-2 2]
b = [7;2]
x = inv(A)*b

So this is pretty easy but lets verify this with a graph.

x = [-2:0.01:2];
y1 = (-3/4).*x + (7/4);
y2 = x + 1;
hold off
plot(x,y1)
hold on
plot(x,y2)
xlabel("x")
ylabel("y")
title("Solving equations by graphing")

In the last program you can see the lines intersect at the location that the matrix method gave us for an answer. So that was easy. So now lets solve another problem. You can use any of the methods you know. Here we go.

$3u+2v-7x+4y-z=9$

$-2u-3v+2x-y+2z = 4$

$7u+v+3x+2y+3z = 5$

$12u + 5v-4x+y-3z = -3$

$-5u-7v-2x-4y+3z = -6$

So the answer is with round-off u=1.3, v=-6.8, x=1.9, y=6.7, and z = -5.5 right? Is this what you got? Did you solve it in a minute like we did? Hmmm....let's learn a new better method that allows us to use the wonderful world of mathematical programs.

First lets start write the system of equations using matrix notations. Let us first put all the coefficients of the equations in a matrix we will call A.

$A = \left(\array{ 3 & 2 & -7 & 4 & -1 \\ -2 & -3 & 2 & -1 & 2 \\ 7 & 1 & 3 & 2 & 3 \\ 12 & 5 & -4 & 1 & -3 \\ -5 & -7 & -2 & -4 & 3}\right)$

For the results we will make a column vector and call it b.

$b = \left(\array{ 9 \\ 4 \\ 5 \\ -3 \\ -6 }\right)$

Then we can write the equations above in matrix format.

$\mathbf{A}\mathbf{x} = \mathbf{b}$

where

$x = \left(\array{ u \\ v \\ x \\ y\\ z }\right)$

While we were just doing one particular example it turns out we created a general equation that would work for any size array (assuming we could take the inverse of it which is not a given with very large arrays). Now we can solve for $$\mathbf{x}$$. First let us "define" the inverse of a matrix as $$\mathbf{A}^{-1} \mathbf{A} = \mathbf{I}$$ where $$\mathbf{I}$$ is called the identity matrix and it acts like the one of matrices. That is $$\mathbf{I} \mathbf{A} = \mathbf{A}$$. Now we can continue to solve this equation. Rewriting our general equation.

$\mathbf{A} \mathbf{x} = \mathbf{b}$

$\mathbf{A}^{-1} \mathbf{A} \mathbf{x} = \mathbf{b} \mathbf{A}^{-1}$

¬ So we multiplied by the inverse of the matrix on each side of the equation and what do we do next?
• We cross out what we did because it is WRONG. Matrix multiplication is not commutative. If you multiply on the left side of the equation you need to multiply on the left side on the other side of the equation. $$\xcancel{\mathbf{A}^{-1} \mathbf{A} \mathbf{x} = \mathbf{b} \mathbf{A}^{-1}}$$

So let us rewrite the last line.

$\mathbf{A}^{-1} \mathbf{A} \mathbf{x} = \mathbf{A}^{-1} \mathbf{b}$

$\mathbf{I} \mathbf{x} = \mathbf{A}^{-1} \mathbf{b}$

$\mathbf{x} = \mathbf{A}^{-1} \mathbf{b}$

And now we can solve this using a mathematical programming language, in this case Octave.

A = [3 2 -7 4 -1;-2 -3 2 -1 2;7 1 3 2 3;12 5 -4 1 -3;-5 -7 -2 -4 3]
b = [9;4;5;-3;-6]
#
# Note * is matrix multiplication; element by element multiplication is .*
#
x = inv(A)*b

Once you know the equation it takes minutes to type it in and solve the problem.

This is just a bit of what matrix multiplication, we have also hinted at transforms in the last section, etc. You can get more detail with numerical methods in the signals and system course.

14.2.3.2: System of equations and Matrices is shared under a not declared license and was authored, remixed, and/or curated by LibreTexts.