Skip to content
Tactiverge

Mathematics · also Computer engineeringLevel 2 · Builder

Engineering formulas as code

Much of engineering mathematics is turning a formula into a calculation you can trust. That means choosing a variable for each quantity and naming its unit, rearranging the formula so the unknown is on its own, converting every input into consistent units, and writing the expression so the computer evaluates it in the intended order. Python applies brackets first, then powers, then multiplication and division from left to right, then addition and subtraction, so the voltage divider must be written v_in * r2 / (r1 + r2). Angles for math.sin and math.cos must be in radians. A quick estimate and a units check catch most slips.

Why it mattersLeaving out one pair of brackets in an LED resistor calculation can give a value hundreds of times too small and burn out the LED.

Learn it

  1. 1Translate a formula into PythonTactiverge School · Level 2
  2. 2Rearrange the formula, then compute: an LED resistorTactiverge School · Level 2
  3. 3The math module: roots, angles and radiansTactiverge School · Level 2