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.