Matlab Tutorial 5: Linear Equations

In this Matlab tutorial we will deal with linear equations, the least square method, condition numbers over & under-determined equations.

Let’s start with an example.

Example 1

We have an equation system with three unknown variables and three equations. What will be the solution to the system below?


Assume a matrix A containing the coefficients multiplied with x, y and z, and a vector with the numbers on the right-hand side of the equations. We can thus rewrite our equations as:

AX=b , where X contains the unknown (w, y and z), A and b are shown below.

b=     A=
  8    3 -2  4
 -5    5  8 -6
-17    9 -2  7

How will we find the solution?

>> X=inv(A)*b


>> X=A\b

both gives a correct answer. The last method produces a Gaussian elimination if A is a quadratic matrix. In our case X becomes:


This is no exact solution, only an approximation. Try also a specific command: Read more »