A8 · Lesson 7 · Lab: first-order models from data
Measuring, simulating and checking first-order systems
A first-order model is only useful once you know its time constant, and in practice that comes from measurements: a scope trace, a logged temperature, a recorded speed. In this lab you'll extract from noisy samples two ways, simulate a heat sink through a power pulse and check the result against the exact solution, and time a falling object with quadratic drag, a nonlinear first-order equation, against its formula.
- The curve is a discharge V on a logarithmic voltage axis.
- On this axis an exponential is a straight line, and its slope gives : the voltage falls by a factor every .
- Change and watch the line's steepness change. Fitting a line to is the most reliable way to read from data.
Predict
You fit a straight line to against for a discharge and get a slope of per ms. What is ?
2 ms. , so the slope is and ms. The intercept gives . Using every sample, rather than one point at 37%, averages out noise.
Name it
Fitting
Two dependable methods for a first-order response:
- Log-linear fit: for a decay toward zero, fit a line to against with
np.polyfit(t, np.log(v), 1); . Leave out samples near zero, where noise dominates the logarithm. - Rise time: for a step response, find where it crosses 10% and 90% of the final value, interpolating between samples, and divide the difference by .
Simulating and checking
Euler's method, , is enough for a first-order system if is a small fraction of ; its error shrinks in proportion to . Always check a simulation against an exact solution where one exists, then trust it where none does.
Quadratic drag
An object falling through air obeys , which is separable (and Bernoulli). It approaches the terminal velocity along
reaching 90% of at .
Worked example
A transistor on a heat sink ( = 5 K/W, = 20 J/K, 25 °C air) dissipates 10 W for 60 s, then nothing. What is its temperature at 120 s?
Show the solution
- Time constant and target. While the power is on, the temperature heads for °C.
- Temperature at 60 s.
- Cooling until 120 s. Then it cools toward 25 °C from there:
- Pulse ratings. A 60 s pulse is too short for it to come anywhere near 75 °C, which is why pulse ratings of power devices are higher than their continuous ratings.
Answer the transistor is at 37.4 °C at 120 s, after peaking at 47.6 °C at 60 s.
Worked example
A 0.1 kg object falls with drag coefficient = 0.01 kg/m. What is its terminal velocity, and when does it reach 90% of it?
Show the solution
- Terminal velocity.
- Time to 90%.
- Compare with no drag. Without drag it would reach 8.91 m/s in 0.91 s; drag stretches the time by about 60%.
Answer the terminal velocity is 9.90 m/s, and it reaches 90% of that at 1.49 s.
Check
A log-linear fit to a discharge gives a slope of 0.5 per ms. What is ?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
Check
An object of 0.05 kg falls with drag coefficient 0.01 kg/m. What is its terminal velocity?
Write units the way you normally would: 1.5 m/s, 1500 mm/s and 0.0015 km/s are the same answer.
Check
Fit from the noisy discharge samples in the starter by a log-linear fit, and set tau (in ms) and V0.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Simulate the heat-sink example with Euler's method, = 0.01 s: with 10 W for s and 0 after. Set T120 to the temperature at 120 s and exact to the formula's value.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Step from rest with = 0.1 kg, = 0.01 kg/m and = 0.0001 s until reaches 90% of . Set t90 to that time, interpolated within the last step, and formula to .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Sample the step response ( = 1.5 ms) every 0.01 ms out to . Find the 10% and 90% crossings by linear interpolation and set tau_est to their difference divided by .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A drink's temperature is logged every 2 minutes in a 20 °C room (data in the starter). Fit Newton's law of cooling by a log-linear fit of , set k (per minute), and set t40 to the predicted time to reach 40 °C from the start at 90 °C.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Explain why
Why is a log-linear fit over many samples better than reading the time at which a decay reaches 37%?
Reading one point uses one sample's worth of information: any noise on that sample, or on the starting value that defines 37%, goes straight into . A straight-line fit to uses every sample, and random errors partly cancel in the average, so the estimate's uncertainty shrinks roughly as one over the square root of the number of points. Taking the logarithm turns the exponential into a line, which makes the fit linear least squares with a closed-form answer. The one caution is the tail: as approaches the noise floor, becomes erratic, so those samples should be left out.
Practice
Keep practicing
5 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.