Solving simultaneous equations using matrices

Matrices are among the most widely used mathematical constructs in computer science. It’s particularly useful in solving a large number of equations fast at a reduced computational cost. Using an everyday example, introducing the basic concepts of matrices and showing how they can be used to solve a system of linear equations.

Tajrin
8 min readJun 10, 2020

We need to develop a fast algorithm when we have to solve a linear system of equations of a large size. In order to solve a system faster, we may need to use a calculator with a big RAM and/or a high clock rate (CPU). But it is not enough when faster means days (or more) if we tackle the problem in the wrong way. [5]

To reduce the computational costs, we have to come up with a good algorithm, a smart idea. But in order to do so, we need to exploit some properties (which are encoded somehow in the coefficients of the matrix) or some structure of the linear system.

Intention

In this article, we’re going to look at matrices. We will solve an apples and oranges problem [1] and will learn:

  • Why matrices are important bricks for solving simultaneous equations.
  • How to use matrices for simultaneous equations.
  • How to find out the price of individual items using matrices when we only have the total bill.

What are matrices?

Matrices are objects that rotate and stretch vectors. And they’re also objects that let us solve these sorts of problems.

Where do matrices come into play?

Now we know that matrix enjoys a particular property that might be crucial to develop a fast algorithm or even to prove that a solution exists, or that the solution has some nice property. Some important points to be noted:

  • A linear system can be seen in a matrix-vector form.
  • Matrices look just like a fancy and compact way to write down a system of equations, mere tables of numbers.
  • Just giving a quick look at the matrix, we can understand if this system has a solution.
  • We can also understand whether the solution is non-negative (meaning that all the components of the solution are non-negative) or not. We wouldn’t be able to draw this conclusion just by looking at the system without trying to solve it.
  • We can also claim that to solve this system how many operations we need (one operation being a single addition/subtraction/division/multiplication) even if we construct a larger system with the same pattern.

How to use matrices for simultaneous equations?

Matrices can be used to compactly write and work with systems of equations, and it can be manipulated in any way that a normal equation can be. This is very helpful when we start to work with systems of equations. It is helpful to understand how to organize matrices to solve these systems. [6]

It is important to do the following:

  • Make sure that all of the equations are written in a similar manner, meaning the variables need to be in the same order.
  • Make sure that one side of the equation is only variables and their coefficients, and the other side is just constants.

Example

Say we walk into a fruit shop and we buy two apples, and three oranges, and suppose that costs 8 dollars. We write it to this equation:

2a + 3b = 8

Here,

a = an apple

b = an orange

Now, say we go to that fruit shop on another day and we buy 10 apples and 1 orange. And the shopkeeper charges us 13 dollars. So the equation is:

10a + 1b = 13

This is an example of a Linear Algebra problem.

We will have to solve these simultaneous equations in order to find out the price of individual apples and oranges. Knowing the prices will help us to decide which offers better value or we can just predict the bill.

We might think the shop must-have sticker prices, why would we do this? But actually, this sort of thing, price discovery, happens all the time in many businesses with complicated products and service agreements and more expensive purchases. Think about what happens when we buy an apartment or a car for instance.

It might be quite difficult to solve all these equations by hand frequently. So, we might want a computer algorithm to do it for us which will save time.

So, the equations are…

2a + 3b = 8

10a + 1b = 13

Constant linear coefficients in these equations: 2, 10, 3, 1

That relates the input variables A and B, to the output 8 and 13. We can consider it as a vector [a, b], that describes the prices of apples and oranges.

Here, 8 and 13 are the cost (how many we might want to buy).

These are just simultaneous equations, and we can write them down in a different way, as a matrix problem:

Consider it as…

[ Known values ] [ Unknown values ] = [Output ]

This matrix is an object with numbers in 2, 3, 10, 1 where:

  • Our first trip: 2, 3
  • Our second trip: 10, 1

Again…

Operations on the matrices…

Now we will multiply this out in the following way:

  • We would multiply the elements in the rows by the elements in the column.
  • We’d multiply the top row times that column: (2 X a) + (3 X b).
  • And we’d say that (2a + 3b) equaled the top row on the right-hand side.
2a + 3b = 8
  • And do the same for the next row, that row times that column is: 10a + 1b, is equal to the row on the bottom on the right-hand side.
10a + 1b = 13

Finally, that looks like our two simultaneous equations:

Two simultaneous equations

Now let’s check what happens if we multiply that matrix by the unit basis (x-axis) vector.

  • Step 1: (2 X 1) + (3 X 0) = 2
  • Step 2: (10 X 1) + (1 X 0) = 10

The result is…

Multiplied the matrix by the unit basis (x-axis) vector

It takes the little unit vector which we called e1 hat, and transforms it to another place:

e1 hat

Let’s do that with the other basis vector. Multiply 2, 3, 10, 1 multiplied by 0, 1:

  • Step 1: (2 X 0) + (3 X 1) = 3
  • Step 2: (10 X 0) + (1 X 1) = 1

And the result…

Multiplied the matrix by the y-axis vector

The other basis vector e2 hat gets transformed over to 3, 1:

e2 hat

So, the complete picture is…

Note

e1 prime = changed e1

e2 prime = changed e2

The matrix 2, 3, 10, 1 is a function that

  • Operates on input vectors and gives us other output vectors, and
  • It moves the basis vectors in some way, it transforms them, it changes the space.

And a set of simultaneous equations here is to find out what vector we need in order to get a transformed product at the position 8, 13.

Conclusion

We learned why matrices are important bricks for solving simultaneous equations, and how to use them. I hope this article gave us an idea of why studying matrices and their properties are of crucial importance in trying to improve linear solvers efficiency.

Definitions of terms used

Simultaneous equations

Simultaneous equations are two or more equations, each with an equal number of unknown variables that are related to each other and are “simultaneous” because they are solved together. [2]

Example: These 2 equations have an equal number of unknown variables…

2a + 3b = 8

10a + 1b = 13

Coefficient

The coefficients are the numbers that are multiplied with the variables. So for the equation 2a + 3b = 8 the coefficients are 2, 3. [3]

Matrix

(Plural: Matrices)

A matrix is a collection/ rectangular arrangement of numbers arranged into rows and columns. Usually, the numbers are real numbers. [4]

Example of a 2×2 matrix (2 rows and 2 columns):

2×2 matrix (2 rows and 2 columns)

Vector

A vector may refer to any of the following:

  • In computer programming, a vector is either a pointer or an array with only one dimension.
  • In mathematics, a vector is a quantity with both a magnitude and direction.
  • In computer graphics, the term vector describes a line with a starting and ending point.
  • In computer security, the term attack vector refers to a particular method for exploiting a system vulnerability.

Unit vector

Unit vectors are vectors whose magnitude is exactly 1 unit, and the unit vectors [0,1] and [1,0] can form together any other vector. [7]

Clock rate (CPU)

The clock rate of a CPU is most useful for providing comparisons between CPUs in the same family, and it is only one of several factors that can influence performance when comparing processors in different families.

But the clock rate alone is generally considered to be an inaccurate measure of performance when comparing different CPUs families. It can sometimes be misleading since the amount of work different CPUs can do in one cycle varies. Software benchmarks are more useful. [8]

[ Last updated on December 24, 2020 ]

References:

  1. https://www.coursera.org/learn/linear-algebra-machine-learning/
  2. https://www.helpingwithmath.com/by_subject/equations_expressions/simultaneous-equations-8ee8.htm
  3. http://mathcentral.uregina.ca/QQ/database/QQ.09.07/h/maddie1.html
  4. https://www.khanacademy.org/math/precalculus/x9e81a4f98389efdf:matrices/x9e81a4f98389efdf:mat-intro/a/intro-to-matrices
  5. https://math.stackexchange.com/questions/160328/what-is-the-usefulness-of-matrices
  6. https://courses.lumenlearning.com/boundless-algebra/chapter/using-matrices-to-solve-systems-of-equations/
  7. https://www.reddit.com/r/learnmath/comments/68l3mh/unit_vector_vs_unit_basis_vector/
  8. https://en.wikipedia.org/wiki/Clock_rate#Comparing

--

--