A4 Python for engineers · Practice
Interpolation and lookup tables
Problems dealt one at a time, with new numbers every time. The kinds you miss come back more often, and you can keep going as long as you like.
Check
Write interp(x, xs, ys) for a single x inside the range of an increasing list xs: find the interval xs[i] <= x <= xs[i + 1] with bisect.bisect_right, then apply the straight-line formula. Set y = [interp(x, xs, ys) for x in queries] for the starter's table and queries.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Build a β-model thermistor table ( = 10 kΩ, β = 3950 K) from 0 to 100 °C every step = 5 °C. At T = 27.5 °C, set r_lin by interpolating linearly in temperature, r_log by interpolating against (kelvins), and err_lin, err_log to their errors in percent against the exact value.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Using a 5 °C table of the same thermistor from 0 to 100 °C, set T_est to the temperature for a measured resistance of Rm = 6500 Ω by interpolating temperature against resistance, and T_exact from the β model, .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The starter gives two loggers' records of the same signal at irregular times, (ta, va) and (tb, vb). Resample both onto a grid of whole seconds that lies inside both records, set g to that grid, d to the differences A minus B on it, and rms to the RMS of d.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A table holds = 4.7 at = 20 and = 5.8 at = 25. What does linear interpolation give at = 21?
Check
Set y to np.interp(x, [1, 2, 3, 4], [10, 20, 15, 5]) for x = 2.25, and y2 to the same value worked out with the straight-line formula yourself.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A sensor's calibration table maps output voltage to pressure: 0 V → 0 kPa, 1 V → 22 kPa, 2 V → 51 kPa, 3 V → 95 kPa. Set p to the pressure for v = 1.7 V by linear interpolation.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
A kind of problem counts as solid once you've got it right on the first try twice in a row. Back to the lesson · Practice every topic in A4