←
PDF 384 / 1160 Example 5.31
→
English · PDF 384
Original PDF page 384
中文 · PDF 384

图 5.8
求解上三角方程组 (5.24) 的步骤。

function x = uppertrisolve(A,b,n)
% uppertrisolve solves A*x=b where A is an nxn upper
triangular matrix with
%nonzero diagonal elements, b is an n vector
%Note the use of the 'colon' notation
%Note that if semicolons are replaced by commas intermediate
results are
%displayed
z=zeros(n,1);
z(n) = b(n)/A(n,n);
for i=n-1:-1:1
    z(i) = (b(i) -A(i,i+1:n)*z(i+1:n))/A(i,i);
end
x=z;
end

例 5.31

使用初等行变换和消元法求解线性方程组

$$\begin{aligned} x + 2y + 3z &= 10 \ -x + y + z &= 0 \ y - z &= 1 \end{aligned}$$

解 用矩阵形式表示,方程组为 $\begin{bmatrix} 1 & 2 & 3 \ -1 & 1 & 1 \ 0 & 1 & -1 \end{bmatrix} \begin{bmatrix} x \ y \ z \end{bmatrix} = \begin{bmatrix} 10 \ 0 \ 1 \end{bmatrix}$

$$\text{Add row 1 to row 2: } \begin{bmatrix} 1 & 2 & 3 \ 0 & 3 & 4 \ 0 & 1 & -1 \end{bmatrix} \begin{bmatrix} x \ y \ z \end{bmatrix} = \begin{bmatrix} 10 \ 10 \ 1 \end{bmatrix}$$

$$\text{Divide row 2 by 3: } \begin{bmatrix} 1 & 2 & 3 \ 0 & 1 & \frac{4}{3} \ 0 & 1 & -1 \end{bmatrix} \begin{bmatrix} x \ y \ z \end{bmatrix} = \begin{bmatrix} 10 \ \frac{10}{3} \ 1 \end{bmatrix}$$

$$\text{Subtract row 2 from row 3: } \begin{bmatrix} 1 & 2 & 3 \ 0 & 1 & \frac{4}{3} \ 0 & 0 & -\frac{7}{3} \end{bmatrix} \begin{bmatrix} x \ y \ z \end{bmatrix} = \begin{bmatrix} 10 \ \frac{10}{3} \ -\frac{7}{3} \end{bmatrix}$$

$$\text{Divide row 3 by } (-\frac{7}{3}): \begin{bmatrix} 1 & 2 & 3 \ 0 & 1 & \frac{4}{3} \ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \ y \ z \end{bmatrix} = \begin{bmatrix} 10 \ \frac{10}{3} \ 1 \end{bmatrix}$$

此时方程组已处于标准的上三角形式,可应用图 5.8 中正式描述的回代步骤求解。