Math 320 — Linear Algebra
Project 1: Option 3 — Mathematical Software (SageMath)
Jack Chen
Project Information
Set: Set 01 — Solving Systems of Linear Equations
Selected Groups: Group A (5 problems) and Group C (3 problems)
Software: SageMath (using SageMath Cell)
Note: Each problem is solved using SageMath's A.solve_right(w) method, which solves the linear system \(A \mathbf{x} = \mathbf{w}\).
Source Code: View on GitHub
Group A — Problems 1 through 5
Problem A1
Solve \(A \mathbf{x} = \mathbf{w}\), where
\[
A = \begin{pmatrix}
1 & 4 & -5 \\
2 & -1 & 8
\end{pmatrix},\qquad
\mathbf{x} = \begin{pmatrix} x_1 \\ x_2 \\ x_3 \end{pmatrix},\qquad
\mathbf{w} = \begin{pmatrix} 0 \\ 9 \end{pmatrix}.
\]
A = matrix(QQ, [[1, 4, -5], [2, -1, 8]])
w = vector(QQ, [0, 9])
print("Solution x =", A.solve_right(w))
Output: Solution x = (4, -1, 0)
Problem A2
Solve \(A \mathbf{x} = \mathbf{w}\), where
\[
A = \begin{pmatrix}
3 & 5 & -4 \\
-3 & -2 & 4 \\
6 & 1 & -8
\end{pmatrix},\qquad
\mathbf{x} = \begin{pmatrix} x_1 \\ x_2 \\ x_3 \end{pmatrix},\qquad
\mathbf{w} = \begin{pmatrix} 7 \\ -1 \\ -4 \end{pmatrix}.
\]
A = matrix(QQ, [[3, 5, -4], [-3, -2, 4], [6, 1, -8]])
w = vector(QQ, [7, -1, -4])
print("Solution x =", A.solve_right(w))
Output: Solution x = (-1, 2, 0)
Problem A3
Solve \(A \mathbf{x} = \mathbf{w}\), where
\[
A = \begin{pmatrix}
1 & 5 & -3 \\
-1 & -4 & 1 \\
-2 & -7 & 0
\end{pmatrix},\qquad
\mathbf{x} = \begin{pmatrix} x_1 \\ x_2 \\ x_3 \end{pmatrix},\qquad
\mathbf{w} = \begin{pmatrix} -4 \\ 3 \\ 5 \end{pmatrix}.
\]
A = matrix(QQ, [[1, 5, -3], [-1, -4, 1], [-2, -7, 0]])
w = vector(QQ, [-4, 3, 5])
print("Solution x =", A.solve_right(w))
Output: Solution x = (1, -1, 0)
Problem A4
Solve \(A \mathbf{x} = \mathbf{w}\), where
\[
A = \begin{pmatrix}
3 & -3 & 3 \\
2 & -1 & 4 \\
3 & -5 & -1
\end{pmatrix},\qquad
\mathbf{x} = \begin{pmatrix} x_1 \\ x_2 \\ x_3 \end{pmatrix},\qquad
\mathbf{w} = \begin{pmatrix} 9 \\ 7 \\ 7 \end{pmatrix}.
\]
A = matrix(QQ, [[3, -3, 3], [2, -1, 4], [3, -5, -1]])
w = vector(QQ, [9, 7, 7])
print("Solution x =", A.solve_right(w))
Output: Solution x = (4, 1, 0)
Problem A5
Solve \(A \mathbf{x} = \mathbf{w}\), where
\[
A = \begin{pmatrix}
1 & 2 & -1 & 3 & 1 \\
2 & 4 & -2 & 6 & 3 \\
-1 & -2 & 1 & -1 & 3
\end{pmatrix},\qquad
\mathbf{x} = \begin{pmatrix} x_1 \\ x_2 \\ x_3 \\ x_4 \\ x_5 \end{pmatrix},\qquad
\mathbf{w} = \begin{pmatrix} 2 \\ 6 \\ 4 \end{pmatrix}.
\]
A = matrix(QQ, [[1, 2, -1, 3, 1], [2, 4, -2, 6, 3], [-1, -2, 1, -1, 3]])
w = vector(QQ, [2, 6, 4])
print("Solution x =", A.solve_right(w))
Output: Solution x = (3, 0, 0, -1, 2)
Group C — Problems 1 through 3
Problem C1
Solve \(A \mathbf{x} = \mathbf{w}\), where
\[
A = \begin{pmatrix}
1 & -2 & -1 & 3 \\
-2 & 4 & 5 & -5 \\
3 & -6 & -6 & 8
\end{pmatrix},\qquad
\mathbf{x} = \begin{pmatrix} x_1 \\ x_2 \\ x_3 \\ x_4 \end{pmatrix},\qquad
\mathbf{w} = \begin{pmatrix} 0 \\ 3 \\ 2 \end{pmatrix}.
\]
A = matrix(QQ, [[1, -2, -1, 3], [-2, 4, 5, -5], [3, -6, -6, 8]])
w = vector(QQ, [0, 3, 2])
print("Solution x =", A.solve_right(w))
Output: ValueError: matrix equation has no solutions
Problem C2
Solve \(A \mathbf{x} = \mathbf{w}\), where
\[
A = \begin{pmatrix}
0 & 1 & -4 \\
2 & -3 & 2 \\
5 & -8 & 7
\end{pmatrix},\qquad
\mathbf{x} = \begin{pmatrix} x_1 \\ x_2 \\ x_3 \end{pmatrix},\qquad
\mathbf{w} = \begin{pmatrix} 8 \\ 1 \\ 1 \end{pmatrix}.
\]
A = matrix(QQ, [[0, 1, -4], [2, -3, 2], [5, -8, 7]])
w = vector(QQ, [8, 1, 1])
print("Solution x =", A.solve_right(w))
Output: ValueError: matrix equation has no solutions
Problem C3
Solve \(A \mathbf{x} = \mathbf{w}\), where
\[
A = \begin{pmatrix}
1 & -4 & 2 \\
0 & 3 & 5 \\
-2 & 8 & -4
\end{pmatrix},\qquad
\mathbf{x} = \begin{pmatrix} x_1 \\ x_2 \\ x_3 \end{pmatrix},\qquad
\mathbf{w} = \begin{pmatrix} 3 \\ -7 \\ -3 \end{pmatrix}.
\]
A = matrix(QQ, [[1, -4, 2], [0, 3, 5], [-2, 8, -4]])
w = vector(QQ, [3, -7, -3])
print("Solution x =", A.solve_right(w))
Output: ValueError: matrix equation has no solutions
Self-Made Problem
Problem Self-Made
Solve \(A \mathbf{x} = \mathbf{w}\), where
\[
A = \begin{pmatrix}
12 & -7 & 15 & -23 \\
5 & 18 & -9 & 41 \\
-11 & 3 & 26 & -14
\end{pmatrix},\qquad
\mathbf{x} = \begin{pmatrix} x_1 \\ x_2 \\ x_3 \\ x_4 \end{pmatrix},\qquad
\mathbf{w} = \begin{pmatrix} 56 \\ -38 \\ 72 \end{pmatrix}.
\]
A = matrix(QQ, [[12, -7, 15, -23], [5, 18, -9, 41], [-11, 3, 26, -14]])
w = vector(QQ, [56, -38, 72])
print("Solution x =", A.solve_right(w))
Output: Solution x = (2095/4676, -3343/4676, 14221/4676, 0)
Complete SageMath Code (All Problems)
The following code block contains all 9 problems. Copy and paste it into SageMath Cell to compute all solutions at once.
A1 = matrix(QQ, [[1, 4, -5], [2, -1, 8]])
w1 = vector(QQ, [0, 9])
print("A1:", A1.solve_right(w1))
A2 = matrix(QQ, [[3, 5, -4], [-3, -2, 4], [6, 1, -8]])
w2 = vector(QQ, [7, -1, -4])
print("A2:", A2.solve_right(w2))
A3 = matrix(QQ, [[1, 5, -3], [-1, -4, 1], [-2, -7, 0]])
w3 = vector(QQ, [-4, 3, 5])
print("A3:", A3.solve_right(w3))
A4 = matrix(QQ, [[3, -3, 3], [2, -1, 4], [3, -5, -1]])
w4 = vector(QQ, [9, 7, 7])
print("A4:", A4.solve_right(w4))
A5 = matrix(QQ, [[1, 2, -1, 3, 1], [2, 4, -2, 6, 3], [-1, -2, 1, -1, 3]])
w5 = vector(QQ, [2, 6, 4])
print("A5:", A5.solve_right(w5))
C1 = matrix(QQ, [[1, -2, -1, 3], [-2, 4, 5, -5], [3, -6, -6, 8]])
v1 = vector(QQ, [0, 3, 2])
print("C1:", C1.solve_right(v1))
C2 = matrix(QQ, [[0, 1, -4], [2, -3, 2], [5, -8, 7]])
v2 = vector(QQ, [8, 1, 1])
print("C2:", C2.solve_right(v2))
C3 = matrix(QQ, [[1, -4, 2], [0, 3, 5], [-2, 8, -4]])
v3 = vector(QQ, [3, -7, -3])
print("C3:", C3.solve_right(v3))
S = matrix(QQ, [[12, -7, 15, -23], [5, 18, -9, 41], [-11, 3, 26, -14]])
s = vector(QQ, [56, -38, 72])
print("Self-Made:", S.solve_right(s))
Interactive SageMath Cell
Use the embedded SageMath Cell below to run the code interactively on this page.
How to Use
- Open https://sagecell.sagemath.org/ in a web browser, or use the embedded cell above.
- Copy the complete SageMath code from the section above, or click Evaluate in the embedded cell.
- The output will display the solution vector for each problem.
- For printing, use your browser's Print function (Ctrl+P or Cmd+P).