Skip to main content
Engineering LibreTexts

18.3: Solution of Linear Systems - MATLAB Backslash

  • Page ID
    55688
  • \( \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}}\)

    We now consider a system of \(n\) linear equations in \(n\) unknowns: \(A x=b\). We presume that the matrix \(A\) is non-singular such that there is indeed a solution, and in fact a unique solution, to this system of equations. We know that we may write this solution if we wish as \(x=A^{-1} b\). There are two ways in which we find \(x\) in MATLAB. Actually, more than two ways: we restrict attention to the most obvious (and worst) and then the best.

    As our first option we can simply write \(x=\operatorname{inv}(A) * b\). However, except for small systems, this will be unnecessarily expensive. This "inverse" approach is in particular very wasteful in the case in which the matrix \(A\) is quite sparse - with many zeros - a situation that arises very (very) often in the context of mechanical engineering and physical modeling more generally. We discuss the root cause of this inefficiency in Unit \(V\).

    As our second option we can invoke the MATLAB "backslash" operator \(\backslash\) (corresponding to the function mldivide) as follows: \(\mathrm{x}=\mathrm{A} \backslash \mathrm{b}\). This backslash operator is essentially a collection of related (direct) solution options from which MATLAB will choose the most appropriate based on the form of \(A\); these options are all related to the "LU" decomposition of the matrix \(A\) (followed by forward and back substitution), as we will discuss in greater detail in Unit V. Note that these LU approaches do not form the inverse of \(A\) but rather directly attack the problem of solution of the linear system. The MATLAB backslash operator is very efficient not only due to the algorithm chosen but also due to the careful and highly optimized implementation.


    This page titled 18.3: Solution of Linear Systems - MATLAB Backslash is shared under a CC BY-NC-SA 4.0 license and was authored, remixed, and/or curated by Masayuki Yano, James Douglass Penn, George Konidaris, & Anthony T Patera (MIT OpenCourseWare) via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.