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.

x+y=10,2x+3y=24x+y=10,\qquad2x+3y=24
Worked example

From the first equation x=10−yx=10-y. Substitution gives 20+y=2420+y=24, so y=4y=4 and x=6x=6.

Maths prerequisite map ↗

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.

See the mathematics
02.557.51002.755.58.2511xy(6, 4)
02.557.51002.755.58.2511xy(6, 4)
x+y=10,2x+3y=24x+y=10,\quad2x+3y=24
  • 10−x10 - x
  • 8−2x38 - \frac{2 x}{3}
Starter reference. The invented ticket constraints hold together at the intersection (6, 4).

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.

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 ↗

Solution tuples (x,y)
{(6, 4)}\left\{\left( 6, \ 4\right)\right\}
Checks
[0, 0]\left[ 0, \ 0\right]
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?

Return to the editor

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?

Choose an answer
Need a hint?
Hint 1

Read the ordered symbol tuple in the call.

Hint 2

Keep the values paired during verification.

Your notesNotes save in this browser when storage is available.