MATLAB Project: Using Backslash to Solve Ax = b Name_______________________________
Purpose: To learn about backslash and why it is the preferred method for solving systems Ax =b
when A is invertible
Prerequisite: Section 2.2 and the discussion of condition number in Section 2.3
MATLAB functions used: \, inv, format, rand, norm, diary, hilb; and ref from Laydata4
Toolbox
Background: This project is about square invertible matrices only. Suppose
is such a matrix and you
want to solve .A=xb
By Theorem 5 in Section 2.2, there is a unique solution to this system. MATLAB
has a special operator called backslash for solving this type of system, and it usually gives excellent
results. It is the method people use in professional settings. To use it, store A and b and type A\b .
Backslash is the best of these methods. It uses an algorithm that is fast and minimizes roundoff error. It
also checks the condition number of the coefficient matrix. If the condition number is large, it will be hard
to get an accurate answer using any numerical method. Fortunately such matrices occur rarely in real
world problems. But if backslash does detect a very large condition number, it will warn you by printing a
message “Matrix is close to singular or badly scaled. Results may be
inaccurate.” Do not ignore such a warning if you ever see it, for it means the solution is probably not
correct to very many digits. If you need more accuracy, consult a numerical analyst.
The inv function also checks the condition number, but calculating 1
−requires a lot more
1. (MATLAB) Here you will use the square matrices in exercises 29, 31, 39 and 41 in Section 2.2. For
each of these, you will create a linear system A=xband solve it using all three methods described above.
You will not see any warnings, so these are “good” problems. You will also see that the solutions are
almost identical as expected.
(a) To get started, determine the path where you will store your work. For example, if you install a flash
drive into the computer’s drive E: drive, type diary E:\solve to open a file called “solve” on
your flash drive.