Solve and checkLesson 13 of 48 · 7 min

Write an equation, then solve it

Represent an equality with Eq and verify a computed solution.

Maths refresher: Keeping an equality balanced

Applying the same reversible operation to both sides preserves the solutions of an equation.

3x+2=11  ⟹  3x=9  ⟹  x=33x+2=11\;\Longrightarrow\;3x=9\;\Longrightarrow\;x=3
Worked example

Subtract 2 from both sides, then divide both sides by the nonzero number 3. Substitution gives 3⋅3+2=113\cdot3+2=11.

Maths prerequisite map ↗

An expression is a mathematical object; an equation states that two expressions are equal. Python assignment binds a name, while Eq constructs a symbolic equation. Keep those roles separate when translating a word problem.

See the mathematics
01.252.53.75504.5913.518xy(3, 11)
01.252.53.75504.5913.518xy(3, 11)
3x+2=11  ⟹  x=33x+2=11\;\Longrightarrow\;x=3
  • 3x+23 x + 2
  • 1111
Starter reference. Solving means finding an input where both sides have the same height.

For a first algebraic equation, solve can return a list of candidate values for the specified symbol. Supply that symbol explicitly. The equation below is linear, so rearranging it by hand provides an independent check of the result.

Substitute each candidate into the original left and right sides, then simplify their difference. That difference is the residual. This makes verification visible rather than assuming that a printed answer meets every condition. Later lessons use solution sets to express domains and families more explicitly.

Does assigning equation = ... itself ask Python to solve the equation?

Write a prediction (optional)

Exact symbolic investigation

Select Run Python with the code unchanged.

Tools
About Python

Python and the course packages can load while you read. Each run starts with fresh user variables; imported modules stay loaded. Stop replaces the worker. Runtime details ↗

Ctrl+Enter or ⌘+Enter runs Python.

Compare with the worked example

Executed from the published Python during the site build. Your own run appears above. Build environment ↗

Equation
3x+2=113 x + 2 = 11
Candidates
[3]\left[ 3\right]
Original residuals
[0]\left[ 0\right]
Worked text output
Equation: Eq(3*x + 2, 11)
Candidates: [3]
Original residuals: [0]

Read the starter result

Equation records the relationship, and Candidates lists the values found by the solver. Each entry in Original residuals is the original left side minus the right side at that candidate.

Edit and compare

Replace sp.Eq(3*x+2,11) with sp.Eq(5*x+2,11). Predict the exact solution. Select Run Python and read Candidates and Original residuals to check it against both sides.

Return to the editor

Scope. Checking an equation is necessary, but additional domain, sign or physical constraints may still exclude a candidate.

Try a fresh case

Which object represents an equation without assigning a value to the symbol x?

Choose an answer
Need a hint?
Hint 1

Distinguish a relationship from a Python operation.

Hint 2

Use the symbolic equality constructor.

Your notesNotes save in this browser when storage is available.