Lite / Textbooks / The Mathematics of Machines / Chapter 1
1. Algebraic modelling
Introduction
Most engineering calculations start as a formula that has to be turned round. You know the supply voltage and the current an LED wants, and you need the resistor. This chapter treats a formula as a model: name the quantities and units, rearrange for the one you need, compute it carefully (in code if it helps) and check the answer is sensible.
Figure 1.1. Rearranging for an LED resistor (described in words)
A 5 V supply, a resistor R and an LED in series. The steps: Vs = I·R + Vf, so R = (Vs − Vf) / I. With Vs = 5 V, Vf = 2 V and I = 0.020 A, R = 3 / 0.020 = 150 Ω.
Explanation
Built from 4 School lessons. Each part is the lesson's own explanation.
1.1 Translate a formula into Python
Two programs compute a voltage divider's output. One says 3.4 V, the other 2211 V. Which pair of brackets is missing?
Python's order of operations
- Brackets. 2. Powers
**(worked right to left). 3. Unary minus, so-3 ** 2is-9. 4.*,/,//,%from left to right. 5.+,-from left to right. When in doubt, add brackets: they cost nothing and show your intent.
A translation recipe
- Name each quantity with its unit:
mass_kg,speed_m_per_s. 2. Replace a fraction bar with/and wrap the whole top and bottom in brackets. 3. Write powers with**. 4. Run it with numbers you can check by hand.
mass_kg = 1.2
speed_m_per_s = 3
energy_j = 0.5 * mass_kg * speed_m_per_s ** 2
print(round(energy_j, 2)) # 5.4Units check and estimate
For E = ½mv²: kg × (m/s)² = kg·m²/s² = J, so the formula is consistent. Estimate: ½ × 1 × 3² ≈ 4.5, close to 5.4. If an answer is out by a factor of 1000 or has the wrong unit, a conversion or bracket is missing.
Derivation: Average speed is total distance over total time
A robot drives d₁ = 120 m in t₁ = 40 s, then d₂ = 80 m in t₂ = 60 s.
Average speed means one steady speed that covers the same total distance in the same total time: v = (d₁ + d₂) / (t₁ + t₂).
Substitute: v = (120 + 80) / (40 + 60) = 200 m / 100 s = 2.0 m/s.
Averaging the two speeds gives (3.0 + 1.33) / 2 ≈ 2.17 m/s, which is wrong because the robot spends longer on the slow leg.
In Python the brackets carry the fraction bar:
(d1_m + d2_m) / (t1_s + t2_s). Without them,d1_m + d2_m / t1_s + t2_sgives 120 + 2 + 60 = 182.0, with meaningless units.
Common mix-ups
Python works out a line from left to right, whatever the operators.
✓ Precedence comes first: ** before * and /, which come before + and −. Left to right only applies within the same level.Extra brackets are bad style.
✓ Brackets that show intent are good style in engineering code, especially around a whole numerator or denominator.
Open the Lite lesson: Translate a formula into Python
1.2 Rearrange the formula, then compute: an LED resistor
An LED needs 20 mA from a 5 V supply. Ohm's law says R = V/I. Which V, and why does the answer come out 1000 times too small?
The calculator
v_supply = 5.0 # V
v_forward = 2.0 # V, from the LED datasheet
current_ma = 20 # mA, wanted LED current
current_a = current_ma / 1000
r_ohm = (v_supply - v_forward) / current_a
power_w = (v_supply - v_forward) * current_a
print(f"R = {r_ohm:.0f} ohm, P = {power_w:.3f} W")Output: R = 150 ohm, P = 0.060 W
Convert first, in one place
Datasheets mix units: mA, kΩ, mV. Convert everything to base SI units (A, Ω, V) once, near the top, in a clearly named variable such as current_a. Then every formula below can be written exactly as it appears in a textbook.
Pick a real part and check it
Resistors come in standard values, such as 120, 150 and 180 Ω. If the calculation gives 140 Ω, choose the next value up (150 Ω), so the current is slightly lower, never higher. Then check the power against the resistor's rating. This lesson is calculation only: any real circuit is built in the circuit simulator first.
Derivation: From Ohm's law to the LED resistor formula
Ohm's law for the resistor: V_R = I · R, with V_R in volts, I in amps and R in ohms.
Divide both sides by I to make R the subject: R = V_R / I.
The LED and the resistor are in series across the supply, so their voltages add: V_supply = V_forward + V_R, giving V_R = V_supply − V_forward.
Substitute: R = (V_supply − V_forward) / I.
Example: (5.0 V − 2.0 V) / 0.020 A = 3.0 / 0.020 = 150 Ω. Power in the resistor: P = V_R · I = 3.0 × 0.020 = 0.060 W, well under a common 0.25 W rating.
Common mix-ups
Use the supply voltage in R = V / I for an LED resistor.
✓ Use the voltage across the resistor, V_supply − V_forward.Unit conversions can be done in your head while reading the code.
✓ Do them in code, once, in named variables, so every reader and every rerun gets them right.
Open the Lite lesson: Rearrange the formula, then compute: an LED resistor
1.3 Ohm's law: V = I × R
Measure the current through a resistor at 1 V, 2 V and 3 V. One number connects all three readings. Can you find it before the graph does?
The law
For a resistor at a steady temperature, V = I × R. Know any two of voltage (V), current (A) and resistance (Ω) and you can find the third. A 220 Ω resistor with 20 mA through it has 0.02 × 220 = 4.4 V across it.
Units are where answers go wrong
Convert first: mA ÷ 1000 → A, kΩ × 1000 → Ω. A current of 5 mA through 2.2 kΩ is 0.005 A × 2200 Ω = 11 V. Then sanity-check: does the answer have the right size and unit?
Reading the graph
Plot current against voltage. For a resistor you get a straight line through the origin: that is what 'ohmic' means. The slope is I ÷ V = 1 ÷ R, so a steeper line means a smaller resistance.
Not everything is ohmic
A filament lamp's line curves over: as it heats, its resistance rises. An LED passes almost nothing below about 1.8–2 V and then the current shoots up. For these, V ÷ I still gives 'the resistance right now', but it changes from point to point.
Derivation: One law, three forms
Start from the experimental finding: for a resistor, current is proportional to voltage, I ∝ V. The constant of proportionality is 1/R, so I = V ÷ R.
Multiply both sides by R: V = I × R.
Divide both sides of V = I × R by I: R = V ÷ I.
Units: volts = amps × ohms. If I is in mA and R in kΩ, the factors of 1000 cancel (10⁻³ × 10³), so mA × kΩ gives volts directly: 5 mA × 2.2 kΩ = 11 V.
Common mix-ups
R = V ÷ I means resistance depends on the voltage you apply.
✓ For a resistor, R is fixed: change V and I changes in proportion, so V ÷ I stays the same. Only non-ohmic parts change.Ohm's law works for every component.
✓ It describes ohmic components. Lamps, LEDs and diodes do not follow a straight line.
Open the Lite lesson: Ohm's law: V = I × R
1.4 Models are functions: input in, output out
A robot must stop within 1 m of an obstacle. What's the fastest it may drive? One graph answers that instantly.
One input, one output
A function f takes an input x and gives exactly one output f(x). In engineering both have units: a spring with f(F) = 2.5F turns a load in newtons into an extension in millimetres. Writing f(x) = … makes the rule something you can test, plot and reuse, just like a Python function.
Shapes tell stories
Linear (straight line): equal input steps give equal output steps, like a spring. Inverse: doubling the input halves the output, like effort on a longer lever. Periodic: the output repeats, like an arm's tip height as it turns. Quadratic: the output grows faster and faster, like stopping distance with speed.
Reading backwards
A requirement is a line on the graph: 'stop within 1 m' is a horizontal line at d = 1. Inputs where the curve is below the line pass. For d = 0.2v + v²/4, that's speeds up to about 1.6 m/s. To solve a linear function backwards, undo its steps: if f(x) = 2x + 10 = 50, then x = (50 − 10) ÷ 2 = 20.
Common mix-ups
If the input doubles, the output doubles.
✓ Only for proportional (linear through zero) functions. Inverse, quadratic and periodic functions behave differently.A graph is just a picture of a table.
✓ It also shows the shape, which tells you how sensitive the output is and where a requirement is met.
Open the Lite lesson: Models are functions: input in, output out
Worked examples
Translate a formula into Python: example 1
Write F = C × 9/5 + 32 in Python and check it at 100 °C.
Solution
temp_f = temp_c * 9 / 5 + 32. Left to right: 100 × 9 = 900, / 5 = 180.0, + 32 = 212.0 °F, which is right for boiling water. temp_c * 9 / (5 + 32) would divide by 37 instead and give about 24.3.
Rearrange the formula, then compute: an LED resistor: example 1
A 12 V supply drives a white LED (3.0 V) at 15 mA. Find R and P.
Solution
V_R = 12 − 3.0 = 9.0 V. I = 15 / 1000 = 0.015 A. R = 9.0 / 0.015 = 600 Ω, so choose the next standard value up, such as 620 Ω. P = 9.0 × 0.015 = 0.135 W: under 0.25 W, but closer than you might like, so a 0.5 W part gives more margin.
Ohm's law: V = I × R: example 1
A 9 V battery is connected across a 450 Ω resistor. What current flows?
Solution
I = V ÷ R = 9 ÷ 450 = 0.02 A = 20 mA.
Ohm's law: V = I × R: example 2
A sensor has 3.3 V across it and draws 1.5 mA. What is its resistance?
Solution
R = V ÷ I = 3.3 ÷ 0.0015 = 2200 Ω (2.2 kΩ).
Models are functions: input in, output out: example 1
A 3D printer's print time is t(m) = 2m + 10 minutes for a part of mass m grams. How long for 25 g? Largest part in 90 minutes?
Solution
t(25) = 50 + 10 = 60 min. 2m + 10 = 90 gives m = 40 g.
Interactive figures, in words
Figure 1.2 from Translate a formula into Python
Pick 'Voltage divider' and step through each expression: in which step does the wrong one go astray? Then try 'Kinetic energy' (is 1 / 2 * m * v ** 2 right?) and 'Average speed' (why is averaging the two speeds wrong?).
The precedence explorer shows a formula, sliders for its inputs, and several Python expressions. For the chosen expression it lists every evaluation step. Example, voltage divider with 5 V, 1000 Ω, 2200 Ω: v_in * r2 / (r1 + r2) → 5 * 2200 / 3200 → 11000 / 3200 → 3.4375 (matches); v_in * r2 / r1 + r2 → 11000 / 1000 + 2200 → 11.0 + 2200 → 2211.0 (does not match).
Figure 1.3 from Ohm's law: V = I × R
Choose the 220 Ω resistor. Record points at 1 V, 2 V, 4 V and 6 V and check that V ÷ I is the same each time. Do the same for the 100 Ω resistor: which line is steeper? Then try the filament lamp and the LED and record three points each. What is different about their V ÷ I?
The V–I plotter shows current (0 to 60 mA) against voltage (0 to 6 V). The 100, 220 and 470 ohm resistors give straight lines through the origin; the 100 ohm line is steepest. The filament lamp's curve bends over as its resistance rises. The LED passes almost no current below about 1.8 V, then rises steeply. Recorded points are listed in a table with V ÷ I for each.
Figure 1.4 from Models are functions: input in, output out
Try each example. Move the input slider and read the output; then move the requirement line and read off which inputs pass. For the stopping-distance example, find the top speed that still stops within 1 m.
The function grapher offers four examples: spring extension (linear), lever effort (inverse), arm tip height (periodic) and stopping distance (quadratic). A slider sets the input and a point marks it on the curve; another slider sets a requirement line. The readout gives the output and the range of inputs that meet the requirement, and a table lists five input–output pairs.
Laboratory
These run in a browser on the full site (they need a faster connection). Simulations are simplified educational models.
- Simulation OS: LED current limiting (Simulation OS experiment)
Predict the current for three resistor values with your rearranged formula, then check each against the model.
Open on the full site - Equation Lab: Functions (Equation Lab exploration)
Fit a straight line to a linear sensor and read the gradient with its units.
Open on the full site - Code Lab (Studio)
Write a function that returns the LED resistor for any supply, forward voltage and current, and test it on the 5 V case.
Open on the full site
Practice
Each question links to its Lite lesson, where your answer is checked on our server and a wrong answer gets a hint. Answers are never sent to your device.
- Which Python line correctly computes V_out = V_in·R2/(R1 + R2)?
Answer it in “Translate a formula into Python” - A robot drives 300 m in 100 s, then 100 m in 100 s. What is its average speed, in m/s?
Answer it in “Translate a formula into Python” - Someone writes power_w = voltage_v / current_a. What does a units check say?
Answer it in “Translate a formula into Python” - An LED with a forward voltage of 1.8 V should carry 15 mA from a 9 V supply. Using r_ohm = (v_supply - v_forward) / (current_ma / 1000), what resistance is needed, in ohms?
Answer it in “Rearrange the formula, then compute: an LED resistor” - Rearrange V = I · R to find I.
Answer it in “Rearrange the formula, then compute: an LED resistor” - There are 6 V across a 1.5 kΩ resistor. What current flows, in milliamps?
Answer it in “Ohm's law: V = I × R” - 5 mA flows through a 2.2 kΩ resistor. What is the voltage across it, in volts?
Answer it in “Ohm's law: V = I × R” - A spring's extension is e(F) = 2.5·F mm, with F in newtons. What is the extension for a 12 N load, in mm?
Answer it in “Models are functions: input in, output out”
Engineering applications
Choosing parts
Rearranged formulas pick resistors, gear ratios and battery sizes. The computed value is then rounded to a part that exists, and the formula is run again forwards to check the rounded part still works.
Unit bugs
Writing 20 instead of 0.020 for a current in amperes makes the resistor a thousand times too small. Converting every quantity to SI units in one place, before calculating, prevents a whole class of mistakes.
Watch (optional)
Streaming video uses a lot of data. Everything you need is in the text.
- “Ohm's law | Physics | Khan Academy” by Khan Academy
- “What is a function? | Functions and their graphs | Algebra II | Khan Academy” by Khan Academy
Summary
- A formula is a model: each symbol is a quantity with a unit and a meaning.
- Rearranging means doing the same operation to both sides until the unknown stands alone.
- Convert to SI units first, compute, then check the size of the answer with an estimate.
- A model is a function: one input gives one output, and its graph shows how the output responds.
Glossary
- Ohm's law
- For a resistor, the voltage across it equals the current through it multiplied by its resistance. Field Guide
- LED current-limiting resistor
- An LED needs a series resistor to set its current, chosen so that the supply voltage minus the LED's forward voltage, divided by the resistance, gives the desired current. Field Guide
- SI prefixes and unit conversion
- SI prefixes are powers of ten written in front of a unit symbol, such as k for 10^3 and m for 10^-3, so that very large and very small quantities stay readable. Field Guide
- Gradient of a straight line
- The gradient of a straight line is the change in y divided by the change in x between any two points on it; in y = mx + c it is m, and c is where the line crosses the y-axis. Field Guide
- Hooke's law (springs)
- For a spring within its elastic limit, the force needed to stretch or compress it is proportional to the change in length: F = k × x. Field Guide
Project: A resistor calculator you can trust
Write a small program that chooses an LED resistor for any supply between 3 V and 12 V. It must convert units in one place, round up to a standard resistor value of your choice, and report the resulting current and the resistor's power.
Deliverables
- The rearranged formula with units
- The program with at least three test cases
- A note on what happens if the supply is below the LED's forward voltage
Write it up on paper or in your own notes. Lite never stores what you write.
References
- Jay Abramson (2015). Algebra and Trigonometry. OpenStax. Link
- Python Software Foundation. The Python Language Reference: Operator precedence. Python Software Foundation. Link
- K. A. Stroud and Dexter J. Booth (2013). Engineering Mathematics, 7th edition. Palgrave Macmillan.
Further reading from the lessons
- Python reference: operator precedence
The official table of which operators bind tighter.