給定矩陣
$$\begin{bmatrix}
-1& 3& 0& 1& 4\\
1&-3& 0& 0&-1\\
2&-6& 2& 4& 0\\
0& 0& 1& 3&-4
\end{bmatrix}$$
求此矩陣的 row-echelor form, reduced row-echelor form.
注意一下,octave不會一步步的解給你看,只會一次到位的給出reduced row-echelor form (rref) 而已。
A = [-1, 3, 0, 1, 4; 1, -3, 0, 0, -1; 2, -6, 2, 4, 0;0, 0, 1, 3, -4]
rref( A )
輸出結果
A =
-1 3 0 1 4
1 -3 0 0 -1
2 -6 2 4 0
0 0 1 3 -4
ans =
1 -3 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
ans得到的就是矩陣的 reduced row-echelor form。
Find all solutions of the given linear system.
$$
\begin{array}{l}
4x_1-3x_2=10\\
8x_1-x_2=10
\end{array}$$
輸入
rref( [4, -3, 10; 8, -1, 10] )
輸出結果
ans =
1 0 1
0 1 -2
由此$x_1=1, x_2 =-2$。
Determine whether the vector $\vec{b}$ is in the span of the vectors $\vec{v}_i$.
$$\vec{b}=\begin{bmatrix}8\\17\\-8\\3\end{bmatrix},
\vec{v}_1=\begin{bmatrix}1\\2\\-1\\0 \end{bmatrix},
\vec{v}_2=\begin{bmatrix} 2\\5\\-2\\5\end{bmatrix},
\vec{v}_3=\begin{bmatrix} -3\\-6\\1\\-8\end{bmatrix},
\vec{v}_4=\begin{bmatrix} 0\\0\\-1\\-4\end{bmatrix},$$
輸入
b = [8; 17; -8; 3];
v1 = [1; 2; -1; 0];
v2 = [2; 5; -2; 5];
v3 = [-3; -6; 1; 8];
v4 = [0; 0; -1; -4];
rref( [v1, v2, v3, v4, b] )
輸出結果如下。
p.s. 如果你得到的結果是小數而不是分數,你可以輸入 format rat 切換 octave 的輸出格式。
ans =
1 0 0 0 45/8
0 1 0 0 1
0 0 1 0 -1/8
0 0 0 1 1/4
由此可知 $\vec{b}=\frac{45}{8}\vec{v}_1+\vec{v}_2-\frac{1}{8}\vec{v}_3+\frac{1}{4}\vec{v}_4$。
找到 $x_1, x_2, x_3, x_4$ 使得下面的等式成立:
$$\begin{bmatrix}x_1 & x_2\\x_3 & x_4\end{bmatrix}
\begin{bmatrix}1 & 1\\1& 0\end{bmatrix}
=\begin{bmatrix}0&1\\3&1\end{bmatrix}$$
這題我解釋一下,以 1-4 的知識點來說,課本是希望你照定義列出下面式子:
$$\left\{\begin{array}{ll}
x_1+x_2=0\\
x_1+0=1\\
x_3+x_4=3\\
x_3+0=1
\end{array}\right.$$
接下來就跟第14題一樣,寫成矩陣,然後解出變數值。
====
或者是你如果已經學到了 1-5,你完全可以直接算
$$\begin{bmatrix}x_1 & x_2\\x_3 & x_4\end{bmatrix}
=\begin{bmatrix}0&1\\3&1\end{bmatrix}
\begin{bmatrix}1 & 1\\1& 0\end{bmatrix}^{-1}$$
輸入
[0, 1; 3, 1] * inv( [1, 1; 1, 0] )
輸出結果
ans =
1 -1
1 2
由此可知 $\begin{bmatrix}x_1 & x_2\\x_3 & x_4\end{bmatrix}
=\begin{bmatrix}1&-1\\1&2\end{bmatrix}$。所以$x_1=1, x_2=-1, x_3=1, x_4=2$。