Skip to main content
Library homepage
 
Engineering LibreTexts

12.4: Solving Systems of Equations

  • Page ID
    84339
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    This is an edited version of Siemers section 2.5.

    We can use matrices to solve systems of linear equations. It is a good idea to read up a bit on some matrix algebra.
    Suppose we have the following system of equations:

    \[\begin{Bmatrix} 3x+2y-z = 10\\ -x+3y+2z = 5\\ x-y-z = -1 \end{Bmatrix}\nonumber\]

    We will solve this system, i.e. find the values of the variables that satisfy all of the equations simultaneously, in two ways: using matrix inverses and using “left division.”

    Method 1: Using the matrix inverse

    Here we create two matrices, one for the coefficients of the variables and one for the constants to the right of the equals signs.

    Coeffs = [ 3  2 -1;
              -1  3  2;
               1 -1 -1];
    Constants = [10;
                  5;
                 -1];

    Then the matrix form of the system of equations is:

    Coeffs * xyz = Constants

    Where the solution is the vector xyz:

    xyz = [x

           y

           z]

    We see that it would be nice to divide both sides by Coeffs. The equivalent operation for matrices is to multiply both sides by the matrix inverse of the Coeffs matrix. Before using the inverse of the Coeffs matrix, we need to verify that the matrix is invertible by computing its determinant:

    Coeffs_det = det(Coeffs)  % =1

    Since the determinant of Coeffs is non-zero, we can solve the system with the inverse:

    xyz1 = inv(Coeffs)*Constants

    % xyz1 =
    %   -2.0000
    %    5.0000
    %   -6.0000

    This tells us that the only solution is x = -2, y = 5, z = -6.

    Method 2: Using left division

    The motivation for this method is complicated. The algorithm is Gaussian elimination, which is not actually a division, but that a division symbol is used by MATLAB to apply this algorithm, as shown below. (If you are interested in the details, you can read the Matlab documentation on left (and right) division of matrices.) We use the same two matrices as in Method 1 and use the backslash \ symbol (be careful to use the correct slash):

    >> xyz2 = Coeffs\Constants

    % xyz2 =
    %   -2.0000
    %    5.0000
    %   -6.000

    This also tells us that the only solution is x = -2, y = 5, z = -6.

    Usually methods 1 & 2 produce nearly identical solutions. Mathworks says: "x = A\b is computed differently than x = inv(A)*b and is recommended for solving systems of linear equations." (https://www.mathworks.com/help/matlab/ref/inv.html)


    This page titled 12.4: Solving Systems of Equations is shared under a CC BY-NC-SA 4.0 license and was authored, remixed, and/or curated by Troy Siemers (APEX Calculus) via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.