Section 2.1 Systems of linear equations
A system of linear equations, such as
can be written in matrix form as \(Ax=b\) where \(A\) is the matrix of coefficients,
and \(b\) is the column vector on the right-hand side:
The Matlab command for solving \(Ax=b\) is very short:
x = A\b
The result is the column vector [1.2632; -1.1053]
, meaning that \(x_1\approx 1.2632\) and \(x_2 \approx -1.1053\text{.}\)
Mathematically, \(x\) could be found as \(x = A^{-1}b\) where \(A^{-1}\) is the inverse matrix. However, this is not a computationally efficient way to solve a linear system. Matlab does not actually compute the inverse matrix when solving a linear system. It chooses one of several algorithms based on the nature of the matrix; usually it is a form of “LU factorization” which is discussed in MAT 532. But even though the formula \(x = A^{-1}b\) is not actually used, it suggests the notation used by Matlab. For two numbers \(a, b\) we can write \(ba^{-1}\) as b/a
, meaning \(b\) divided by \(a\text{.}\) If the order of multiplication was important (as it is for matrices), then perhaps \(a^{-1}b\) could be written as a\b
, meaning \(b\) divided by \(a\) from the left. We do not actually “divide a vector by a matrix” but the notation A\b
can remind us of \(A^{-1}b\text{.}\)
Example 2.1.1. Solve and verify.
Write a Matlab script which solves the linear system
and then plug the solution into the left hand side to check that the solution is correct.
A = [5 3 0; -2 1 -6; 0 3 1]; b = [2; 0; 3]; x = A\b; disp(x) disp(A*x)