Matlab solves system of equations

Solving a system of equations with two unknowns is a very easy cake to bite but when the number of unknown exceed two, solving the system of equation becomes complicated and time consuming.

In this post we are going to show you how you can use your computer and Matlab to solve a system of many equations.

Caution: the following technique works only when the number of equations and the number of unknown are the same. We will solely work will linear equations

Can Matlab solve system of equations?

Yes, Matlab can help you easily solve system of equations. Lets jump into some examples and show you how you go about it.


Using Matlab to Solve a system of equation with two unknowns

Let’s consider the following system of equations


The above equation can be written in the matrix form


The equation can be rewritten as


Now we are set to use Matlab!

A=[2 3;1 1];

The last line does not have ; at the end.

You will see an answer like this


Which simply means that


Let’s elaborate a little more in details here before moving forward. What we have done above is the following.

We have written the equation in the form




So to have at the end the equation on the form


Example 2: System of equation with three unknowns

let’s consider the following system of equations


Using the same technique we used above we can write the system in the following form


Giving commands to Matlab will look like the following

A=[1 3 -2;3 2 -1;2 -1 -3];

To end up with the following result


Final thought

If you are working on a system of equations where the number of unknown is equal to the number of equations, this method is a good way to go. This restriction is due to the fact that using the system of matrices to solve such system of equations requires that the matrix A is invertible. If there is no possibilities of finding the inv(A) then this method is totally useless.

Content you might like:

Write a function that find the volume of a 3D rectangle in Matlab
Scalar functions in Matlab: e Matlab, Cosine function and more
Left division vs Right Matrix division – Matlab
Convert numbers from Polar to Cartesian and vice versa


Related Posts