Thursday, September 17, 2015

Matlab Tutorial Part 3 - Solve a System of Linear Equations

In today's part I want to show how to solve a system of linear equations. A system of linear equations has the form A * x = b, where A is the matrix representing the coefficients and b the right side of the equation system. We want to solve for x.
For this we simpy have to input A and x in Matlab and then call the command

x = linsolve(A, b)

One example:
We want to solve

x1   + x2     + x3   = 5
2x1             + 3x3 = 2
          10x2 - x3    = 1

Thus in Matlab we enter the matrix of coefficients (A = [1, 1, 1; 2, 0, 3; 0, 10, -1]) as well as the vector b (b = [5;2;1]).
After entering x = linsolve(A, b) Matlab returns the correct answer

x =

   15.6250
   -0.8750
   -9.7500

No comments:

Post a Comment