CU Mechanical Engineering

course specific Matlab tutorials



Solving Systems of Linear Equations

One of the very useful applications of matrices and vectors is the ability to easily and quickly solve systems of linear equations. Lets suppose you wanted to solve the 3rd order system:


1*x1 + 2*x2 + 3*x3 = 6

4*x1 + 8*x2 + 2*x3 = 3

3*x1 + 2*x2 + 8*x3 = 12

The best way to set up this problem is to organize it in the form: Ax=b where 'A' is the coefficient matrix, 'x' is the vector to solve for and 'b' is the vector of values on the right side of the equations. We start by setting up the matrix 'A'.


>> A = [1 2 3; 4 8 2; 3 2 8]



A =



     1     2     3

     4     8     2

     3     2     8

We next define the vector 'b'.


>> b = [6; 3; 12]



b =



     6

     3

    12

We can now solve for the vector 'x' by multiplying each side by the inverse of A or A^-1


>> x = A^-1*b



x =



   -2.2500

    0.9750

    2.1000

We can easily check that Ax=b:


>> A*x



ans =



    6.0000

    3.0000

   12.0000

This application of solving linear systems can be extremely useful in applications of solving resistance networks for electrical circuits or any other application where a system can be reduced to a set of linear equations.

Now that you can solve Linear systems, let's work on Vector Operations!