Solving linear systems with Matlab
Solving linear systems of equations with Matlab consists of a few steps.
- Model your engineering problem as a system of linear equations. (NOTE: This is the hard part.)
- Rewrite your linear system in general form with unknowns on the left and known (constants) on the right side of the equations.
- [Optional] Write your linear system as a single Matrix Equation of the form:
Ax=b
WhereA
is a matrix of the coefficients of the unknowns of each equation andb
is a column vector that contains the constants (right hand side of each equation). - Enter the coefficient matrix in Matlab as
A
. - Enter the right hand side data values of your equations as column vector
b
. - Execute the Matlab matrix equation solve command:
x = A\b
This will give you a vector variable of solutions x.
The \
operator performs Gaussian elimination on the matrix equation.
It is just that simple.
Depending upon how many unknowns you have and thus how large your matrix is,
the \
operation can involve an enormous amount of computation.
However, you don’t have to be concerned about that.
So long as you have mathematically modeled your problem correctly and
entered the coefficient matrix, A
, and data vector, b
, correctly,
Matlab will take care of the rest.