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.
Subtract 2 from both sides, then divide both sides by the nonzero number 3. Substitution gives .
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.
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.
Your saved draft is open. To use the published code, select Restore example in Tools. Use Recover draft to bring back your code.
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.
Execution error
Technical error details
Your result
Python text output
Compare with the worked example
Executed from the published Python during the site build. Your own run appears above. Build environment ↗
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.
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?
Need a hint?
Hint 1
Distinguish a relationship from a Python operation.
Hint 2
Use the symbolic equality constructor.