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 equations 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 a system of equations?

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

Matlab-solves-system-of-equations

Using Matlab to Solve a system of equation with two unknowns

Let’s consider the following system of equations

Matlab-solves-system-of-equations

The above equation can be written in the matrix form

Matlab-solves-system-of-equations

The equation can be rewritten as

Matlab-solves-system-of-equations

Now we are set to use Matlab!

A=[2 3;1 1];
B=[8;3];
X=inv(A)*B

The last line does not have; at the end.

You will see an answer like this

Matlab-solves-system-of-equations

Which simply means that

Matlab-solves-system-of-equations

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

Matlab-solves-system-of-equations

Where

Matlab-solves-system-of-equations

So to have at the end the equation on the form

Matlab-solves-system-of-equations

Example 2: System of equation with three unknowns

let’s consider the following system of equations

Matlab-solves-system-of-equations

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

Matlab-solves-system-of-equations

Giving commands to Matlab will look like the following

A=[1 3 -2;3 2 -1;2 -1 -3];
B=[1;2;13];
X=inv(A)*B

To end up with the following result

Matlab-solves-system-of-equations

Final thought

If you are working on a system of equations where the number of unknowns 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 are no possibilities of finding the inv(A) then this method is totally useless.

Posts you might like:

Write a function that finds 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

tchouken2

Related Posts