from edumath.linear_algebra import solve_linear_system, validate_solution_vector
A = [[1, 1], [1, -1]]
b = [5, 1]
solution = solve_linear_system(A, b)
print(solution)
print(validate_solution_vector(solution, A, b).message)[3. 2.]
Correct.
A system of linear equations asks for values that satisfy several linear conditions at the same time. In two variables, each equation is a line. Solving the system means finding where the lines intersect.
Linear algebra writes systems compactly as
\[ A\mathbf{x}=\mathbf{b}. \]
Here \(A\) is the coefficient matrix, \(\mathbf{x}\) is the vector of unknowns, and \(\mathbf{b}\) is the right-hand-side vector.
By the end of this lesson, you should be able to:
The system
\[ \begin{aligned} x+y &= 5,\\ x-y &= 1 \end{aligned} \]
can be written as
\[ \underbrace{\begin{bmatrix}1&1\\1&-1\end{bmatrix}}_{A} \underbrace{\begin{bmatrix}x\\y\end{bmatrix}}_{\mathbf{x}} = \underbrace{\begin{bmatrix}5\\1\end{bmatrix}}_{\mathbf{b}}. \]
The first row of \(A\) stores the coefficients in the first equation. The second row stores the coefficients in the second equation.
Elimination replaces equations by easier equations without changing the solution set. The main legal moves are:
These moves are legal because they do not change which values make all equations true.
If a solution makes equation 1 true and equation 2 true, then it also makes “equation 2 minus equation 1” true. This is why elimination can remove a variable without losing the real solution.
Solve
\[ \begin{aligned} x+y &= 5,\\ x-y &= 1. \end{aligned} \]
Add the two equations:
\[ (x+y)+(x-y)=5+1. \]
This gives \(2x=6\), so \(x=3\). Substitute into \(x+y=5\):
\[ 3+y=5 \quad \Rightarrow \quad y=2. \]
The solution is \((x,y)=(3,2)\). Check it:
\[ 3+2=5, \qquad 3-2=1. \]
Two nonparallel lines intersect at one point. Algebraically, the equations are independent enough to determine one vector.
Parallel distinct lines never meet. Algebraically, elimination may produce an impossible statement such as
\[ 0=5. \]
The two equations describe the same line. Elimination may produce
\[ 0=0. \]
This means one equation was redundant, not that every point in the plane is a solution. The solution set is the whole line described by the remaining equation.
The statement \(0=0\) does not mean “the answer is zero.” It means the equation added no new restriction. You must describe the remaining free variable or line of solutions.
Solving a linear system means keeping the solution set unchanged while making the equations easier to read.
Guess first. In \(A\mathbf{x}=\mathbf{b}\), where do the unknowns go?
Guided exercise.
For
\[ \begin{aligned} 2x+y&=8,\\ -x+3y&=7, \end{aligned} \]
write
\[ A=\begin{bmatrix}2&1\\-1&3\end{bmatrix}, \qquad \mathbf{x}=\begin{bmatrix}x\\y\end{bmatrix}, \qquad \mathbf{b}=\begin{bmatrix}8\\7\end{bmatrix}. \]
The unknowns are collected in the vector \(\mathbf{x}\). The coefficients belong in \(A\), and the constants belong in \(\mathbf{b}\).
Checkpoint. Write \(3x-2y=1\) and \(5x+y=9\) as \(A\mathbf{x}=\mathbf{b}\).
Guess first. For \(x+y=6\) and \(x-y=2\), should adding the equations eliminate \(x\) or \(y\)?
Guided exercise.
Solve
\[ \begin{aligned} x+y&=6,\\ x-y&=2. \end{aligned} \]
Add the equations:
\[ (x+y)+(x-y)=6+2. \]
The \(y\) terms cancel, so
\[ 2x=8 \quad \Rightarrow \quad x=4. \]
Substitute into the first equation:
\[ 4+y=6 \quad \Rightarrow \quad y=2. \]
The solution is \((4,2)\).
Checkpoint. Solve \(x+y=9\) and \(x-y=3\) using the same add-the-equations strategy.
Guess first. If a point satisfies only one equation in a two-equation system, is it a solution of the system?
Guided exercise.
Check whether \((2,3)\) solves
\[ \begin{aligned} x+y&=5,\\ 2x-y&=1. \end{aligned} \]
Substitute into both equations:
\[ 2+3=5 \quad \text{true}, \]
and
\[ 2(2)-3=1 \quad \text{true}. \]
Both equations are true, so \((2,3)\) is a solution.
Checkpoint. Check whether \((1,4)\) solves \(x+y=5\) and \(2x-y=1\).
Guess first. What does \(0=7\) mean in a system-solving problem?
Guided exercise.
Consider
\[ \begin{aligned} x+y&=3,\\ 2x+2y&=10. \end{aligned} \]
Twice the first equation gives \(2x+2y=6\), but the second equation says \(2x+2y=10\). These cannot both be true. Elimination would produce an impossible statement such as \(0=4\), so the system has no solution.
Checkpoint. Classify \(x+y=4\) and \(2x+2y=8\). Explain why the answer is not “one solution.”
Guess first. If two equations describe the same line, does every point in the plane solve the system?
Guided exercise.
For
\[ x+y=4, \qquad 2x+2y=8, \]
the second equation is twice the first. The system has infinitely many solutions, but only on the line \(x+y=4\). One way to describe them is
\[ (x,y)=(t,4-t) \]
for any real number \(t\).
Checkpoint. Describe the solutions of \(x-y=1\) and \(2x-2y=2\) using a parameter.
Use this checkpoint to practice classification, substitution, and elimination moves.
Use computation to check your elimination work. SymPy can solve systems exactly and show row-reduced forms.
[3. 2.]
Correct.