A87 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

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=5e−t/τ 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 e every τ.
  • Change τ and watch the line's steepness change. Fitting a line to ln⁡v is the most reliable way to read τ from data.

Predict

You fit a straight line to ln⁡v against t for a discharge and get a slope of −0.5 per ms. What is τ?

Name it

Fitting τ

Two dependable methods for a first-order response:

  • Log-linear fit: for a decay toward zero, fit a line to ln⁡v against t with np.polyfit(t, np.log(v), 1); τ=−1/slope. 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 ln⁡9=2.197.

Simulating and checking

Euler's method, yn+1=yn+hf(tn,yn), is enough for a first-order system if h is a small fraction of τ; its error shrinks in proportion to h. 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 mv˙=mg−bv2, which is separable (and Bernoulli). It approaches the terminal velocity vt=mg/b along

v=vttanh⁡gtvt

reaching 90% of vt at t=vtgtanh−1⁡0.9=1.472vtg.

Worked example

A transistor on a heat sink (Rθ = 5 K/W, Cθ = 20 J/K, 25 °C air) dissipates 10 W for 60 s, then nothing. What is its temperature at 120 s?

Show the solution
  1. Time constant and target. τ=RθCθ=100s While the power is on, the temperature heads for 25+10×5=75 °C.
  2. Temperature at 60 s. T(60)=25+50(1−e−0.6)=47.6°C
  3. Cooling until 120 s. Then it cools toward 25 °C from there: T(120)=25+22.6e−0.6=37.4°C
  4. 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 b = 0.01 kg/m. What is its terminal velocity, and when does it reach 90% of it?

Show the solution
  1. Terminal velocity. vt=0.1×9.81/0.01=9.90m/s
  2. Time to 90%. t=9.909.81tanh−1⁡0.9=1.009×1.472=1.49s
  3. 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, h = 0.01 s: CT˙=P(t)−(T−25)/R with 10 W for t<60 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 mv˙=mg−bv2 from rest with m = 0.1 kg, b = 0.01 kg/m and h = 0.0001 s until v reaches 90% of vt. Set t90 to that time, interpolated within the last step, and formula to vtgtanh−1⁡0.9.

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−e−t/τ (τ = 1.5 ms) every 0.01 ms out to 8τ. Find the 10% and 90% crossings by linear interpolation and set tau_est to their difference divided by ln⁡9.

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 T−20, 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%?

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.