Solve and checkLesson 15 of 48 · 7 min
Solve a linear system
Interpret linsolve output as a jointly constrained tuple.
Maths refresher: Two equations together
A solution of a system is an input combination satisfying every equation, not one equation at a time.
From the first equation . Substitution gives , so and .
A system requires all its equations to hold at the same time. Solving each equation separately without connecting shared variables can produce incompatible values. linsolve handles linear systems and returns a set of ordered solution tuples.
State the variable order explicitly. A tuple for (x,y) gives the x value first and the y value second, regardless of a story’s naming conventions. Substitute the whole tuple into every original residual, the difference between the two sides, to check the system.
The invented ticket problem below has a total count and a total revenue constraint. Its unique solution is exact. Other systems can have no solutions or a family with free parameters; the output set communicates that structure rather than always yielding one pair.
Does a pair satisfying only the total-count equation solve the full system?
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
Solution tuples (x,y): {(6, 4)}
Checks: [0, 0]
Read the starter result
Read the entries in Solution tuples (x,y) in the stated order. In Checks, each zero checks one original equation using the same pair.
Edit and compare
In the residuals line, replace 2*x+3*y-24 with 2*x+3*y-25. Select Run Python. Read Solution tuples (x,y) and Checks. Does the new solution also give two nonnegative integer ticket counts?
Scope. Linear algebra solves the mathematical system; integer counts and nonnegativity may impose additional modelling constraints.
Try a fresh case
For linsolve(equations,(u,v)), how should a result tuple (2,5) be read?
Need a hint?
Hint 1
Read the ordered symbol tuple in the call.
Hint 2
Keep the values paired during verification.