---
title: Modeling with first-order equations
heading: Rate in minus rate out
eyebrow: A8 · Lesson 13 · Modeling
xp: 40
---

::: hook
A power transistor's datasheet gives two numbers that decide whether it survives: a thermal resistance, in kelvin per watt, and a thermal capacitance, in joules per kelvin. Together they make a first-order equation exactly like an RC circuit, with temperature in place of voltage and power in place of current. So do a tank of brine with fresh water flowing through, a room warming in the sun, and a drug clearing from the bloodstream. One recipe builds all of these models: the rate of change of what's stored equals the rate it comes in minus the rate it goes out.
:::

::: play
- A transistor dissipating $P$ heats up from ambient (25 °C). Its junction has thermal resistance $R_\theta$ to the air and thermal capacitance $C_\theta$.
- Change $P$ and $R_\theta$: they set the final temperature. Change $C_\theta$: it sets only how fast you get there.
- The datasheet limit is 150 °C. Find settings that stay below it.
:::
:::

```sim plot
view: graph
x: t = 0..400 s
y: T = 0..200 °C
slider: P = 1..20 step 0.5 = 10 W
slider: Rth = 1..10 step 0.5 = 5
slider: Cth = 5..60 step 1 = 20
plot: 25 + P*Rth*(1 - exp(-t/(Rth*Cth))) | label: junction temperature
plot: 150 | label: limit | color: ch3
readout: final temperature = 25 + P*Rth °C | digits: 4
readout: thermal time constant = Rth*Cth s | digits: 4
```

::: predict
## The transistor's heatsink is swapped for one with half the thermal resistance and the same heat capacity. What happens?

- [x] It runs cooler, and reaches its final temperature in half the time
- [ ] It runs cooler but takes twice as long to settle
- [ ] Same final temperature, faster
- [ ] It runs hotter

::: reveal
Both improve. The final rise above ambient is $PR_\theta$, so it halves; the time constant is $R_\theta C_\theta$, so it halves too. It's an RC circuit: a smaller resistance charges the same capacitor faster, and to a lower final value when it's fed by a current.
:::
:::

::: nameit
## The balance law

For any stored quantity $Q$ (charge, heat, mass, salt):

$$\frac{dQ}{dt} = (\text{rate in}) - (\text{rate out})$$

Write each rate in terms of $Q$ and the inputs, and you have the model. Linear rates give linear first-order equations, solved by lesson 4.

## Thermal circuits

Heat stored is $C_\theta T$; heat flows out through $R_\theta$ at $\frac{T - T_a}{R_\theta}$; power $P$ flows in:

$$C_\theta\frac{dT}{dt} = P - \frac{T - T_a}{R_\theta} \quad\Longrightarrow\quad T = T_a + PR_\theta\left(1 - e^{-t/R_\theta C_\theta}\right)$$

| Thermal | Electrical |
|---|---|
| Temperature $T$ (K) | Voltage $v$ |
| Heat flow $P$ (W) | Current $i$ |
| Thermal resistance $R_\theta$ (K/W) | Resistance $R$ |
| Heat capacity $C_\theta$ (J/K) | Capacitance $C$ |

A short pulse of power heats the junction less than steady power would, because the heat capacity absorbs it first. That's why datasheets allow higher pulsed power.

## Mixing

A tank of volume $V$ holds an amount $S$ of a substance. Liquid flows in at rate $r$ with concentration $c_\text{in}$ and out at the same rate, well mixed:

$$\frac{dS}{dt} = rc_\text{in} - r\frac{S}{V} \quad\Longrightarrow\quad S \to c_\text{in}V, \quad \tau = \frac{V}{r}$$

The time constant is the time to flow one tank's volume through.

## Newton's law of cooling

$\dot T = -k(T - T_a)$: the same thermal circuit with no power input, $k = \frac{1}{R_\theta C_\theta}$.
:::

::: example
## A transistor dissipates 10 W with $R_\theta$ = 5 K/W and $C_\theta$ = 20 J/K, in 25 °C air. How hot is it after 60 s, and finally?

::: solution
1. **Time constant.**
   $$\begin{aligned} \tau &= 5 \times 20 \\ &= 100\ \text{s} \end{aligned}$$
2. **Final temperature.** The final rise is $10 \times 5 = 50$ K, so it heads for 75 °C.
3. **Temperature after 60 s.**
   $$\begin{aligned} T &= 25 + 50(1 - e^{-0.6}) \\ &= 25 + 50 \times 0.451 \\ &= 47.6\ \text{°C} \end{aligned}$$

**Answer:** 47.6 °C after 60 s, and 75 °C finally.
:::
:::

::: example
## A 100 L tank holds 10 kg of salt. Fresh water flows in at 5 L/min and the mixture out at 5 L/min. How much salt is left after 30 min?

::: solution
1. **Salt balance.**
   $$\dot S = -\frac{5}{100}S$$
2. **Solve.** With $t$ in minutes,
   $$S = 10e^{-t/20}$$
3. **After 30 min.**
   $$\begin{aligned} S &= 10e^{-1.5} \\ &= 2.23\ \text{kg} \end{aligned}$$
4. **The time constant.** The time constant, 20 min, is the time to pass one tank's worth of water.

**Answer:** 2.23 kg of salt is left after 30 min.
:::
:::

::: example
## Coffee at 90 °C in a 20 °C room cools to 60 °C in 10 minutes. When does it reach 40 °C?

::: solution
1. **Newton's law of cooling.** The difference from the room decays exponentially:
   $$T - 20 = 70e^{-kt}$$
2. **Find $k$.** From $40 = 70e^{-10k}$,
   $$\begin{aligned} k &= \frac{\ln(70/40)}{10} \\ &= 0.0560 \end{aligned}$$
   per minute.
3. **Time to 40 °C.** For 40 °C the difference is 20, so $e^{-kt} = \frac{20}{70}$:
   $$\begin{aligned} t &= \frac{\ln 3.5}{0.0560} \\ &= 22.4\ \text{min} \end{aligned}$$
4. **Why it slows.** The second 20 °C of cooling takes longer than the first 30 °C, because the rate falls with the difference.

**Answer:** the coffee reaches 40 °C after 22.4 minutes.
:::
:::

::: check
given: P = 5 | 12; Rth = 3 | 8; Ta = 25 | 40
answer: Ta + P*Rth
unit: °C

## A device dissipates {P} W through a thermal resistance of {Rth} K/W into {Ta} °C air. What is its final temperature?

::: right
Right. $T_a + PR_\theta$ = {answer}.
:::

::: misses
- [P*Rth] That's the rise above ambient. Add the ambient temperature.
- [Ta + P/Rth] Temperature rise is power times thermal resistance, like $V = IR$.
- [any] Not yet. Final temperature: ambient plus $PR_\theta$.
:::
:::

::: check
given: Rth = 2 | 6; Cth = 15 | 40
answer: Rth*Cth
unit: s

## What is the thermal time constant for $R_\theta$ = {Rth} K/W and $C_\theta$ = {Cth} J/K?

::: right
Right. $R_\theta C_\theta$ = {answer}, with K/W × J/K = s.
:::

::: misses
- [Cth/Rth] Like $RC$: multiply.
- [any] Not yet. $\tau = R_\theta C_\theta$.
:::
:::

::: check
given: P = 8 | 15; Rth = 4 | 5; Cth = 10 | 30; t = 20 | 60
answer: 25 + P*Rth*(1 - exp(-t/(Rth*Cth)))
unit: °C
tolerance: 0.5%

## A device starts at 25 °C ambient and dissipates {P} W, with $R_\theta$ = {Rth} K/W and $C_\theta$ = {Cth} J/K. What is its temperature after {t} s?

::: right
Right. $25 + PR_\theta(1 - e^{-t/R_\theta C_\theta})$ = {answer}.
:::

::: misses
- [25 + P*Rth] That's the final temperature; it isn't there yet.
- [25 + P*Rth*exp(-t/(Rth*Cth))] It rises toward the final value: $1 - e^{-t/\tau}$.
- [any] Not yet. First-order rise toward $25 + PR_\theta$.
:::
:::

::: check
given: S0 = 5 | 20; V = 200 | 50; r = 10 | 5; t = 10 | 30
answer: S0*exp(-r*t/V)
unit: kg
tolerance: 0.5%

## A {V} L tank holds {S0} kg of salt; fresh water flows through at {r} L/min. How much salt is left after {t} min?

::: right
Right. $S_0e^{-rt/V}$ = {answer}.
:::

::: misses
- [S0 - r*t*S0/V] The outflow concentration falls as the salt goes, so the decay is exponential.
- [S0*exp(-V*t/r)] The time constant is $V/r$; the exponent is $-rt/V$.
- [any] Not yet. $\dot S = -\frac{r}{V}S$.
:::
:::

::: check
given: cin = 0.05 | 0.2; V = 100 | 400
answer: cin*V
unit: kg

## Brine at {cin} kg/L flows into a {V} L tank and the mixture flows out at the same rate. How much salt does the tank hold in the long run?

::: right
Right. The tank fills up to the inflow concentration: $c_\text{in}V$ = {answer}.
:::

::: misses
- [cin] That's the concentration. Multiply by the volume.
- [any] Not yet. Set $\dot S = 0$.
:::
:::

::: check
given: P = 30 | 40; Rth = 5 | 6; Cth = 20 | 40; Tmax = 125 | 150
answer: -Rth*Cth*ln(1 - (Tmax - 25)/(P*Rth))
unit: s
tolerance: 0.5%

## A device at 25 °C ambient starts dissipating {P} W ($R_\theta$ = {Rth} K/W, $C_\theta$ = {Cth} J/K). Its final temperature would be too high. How long can the pulse last before it reaches {Tmax} °C?

::: right
Right. Solve $25 + PR_\theta(1 - e^{-t/\tau}) = T_\text{max}$: {answer}.
:::

::: misses
- [Rth*Cth] That's the time constant, not the time to reach {Tmax} °C.
- [any] Not yet. $1 - e^{-t/\tau} = \frac{T_\text{max} - 25}{PR_\theta}$.
:::
:::

::: check
kind: parts
given: T0 = 80 | 90; Ta = 20 | 25; T1 = 60 | 50; t1 = 5 | 10

## A drink at {T0} °C sits in a room at {Ta} °C and is at {T1} °C after {t1} min.

::: part
answer: ln((T0 - Ta)/(T1 - Ta))/t1
tolerance: 0.5%

### What is $k$ in Newton's law of cooling, per minute?

::: misses
- [(T0 - T1)/t1] The temperature difference decays exponentially, not linearly.
- [any] $T - T_a = (T_0 - T_a)e^{-kt}$.
:::
:::

::: part
answer: Ta + (T0 - Ta)*exp(-2*ln((T0 - Ta)/(T1 - Ta)))
unit: °C
tolerance: 0.5%

### What is its temperature after $2t_1$?

::: misses
- [any] Each interval of $t_1$ multiplies the difference by the same factor.
:::
:::
:::

::: check
kind: derivation
vars: V = 50..200, q = 1..10, Q = 1..20, t = 0..60

## A $V$-liter tank holding $Q$ kg of salt is flushed with fresh water at $q$ L/min, with the mixture leaving at the same rate.

::: step
answer: -q/V

### The salt obeys $\dot S = -\frac qVS$. What is the decay rate coefficient?
:::

::: step
answer: Q*exp(-q*t/V)

### What is $S(t)$?
:::

::: right
Right. The salt decays with time constant $V/q$, the time to replace one tankful.
:::
:::

::: explain
## Why does a power transistor tolerate a short pulse of power that would destroy it if applied continuously?

::: model
Its temperature can't jump: heat has to fill the thermal capacitance first, so the junction warms with time constant $R_\theta C_\theta$ toward a final value of $T_a + PR_\theta$. If the pulse ends well before the temperature gets near that final value, the junction never reaches it. The same power held for many time constants would drive the junction all the way up, past its limit. Short pulses are limited by the heat capacity, long ones by the thermal resistance.
:::
:::

::: practice

::: check
given: T0 = 90 | 60; Ta = 20 | 25; k = 0.1 | 0.02; t = 10 | 30
answer: Ta + (T0 - Ta)*exp(-k*t)
unit: °C
tolerance: 0.5%

## A part cools by $\dot T = -\given{k}(T - T_a)$ from {T0} °C into {Ta} °C air. What is its temperature after {t} s?

::: misses
- [T0*exp(-k*t)] It cools toward ambient.
- [any] $T_a + (T_0 - T_a)e^{-kt}$.
:::
:::

::: check
given: V = 50 | 500; r = 2 | 20
answer: V/r
unit: min

## What is the time constant of a {V} L well-mixed tank with {r} L/min flowing through?

::: misses
- [r/V] Volume over flow rate.
- [any] $V/r$.
:::
:::

::: check
given: Tmax = 125 | 150; Ta = 25 | 50; Rth = 2 | 4
answer: (Tmax - Ta)/Rth
unit: W

## How much continuous power can a part with $R_\theta$ = {Rth} K/W dissipate in {Ta} °C air without exceeding {Tmax} °C?

::: misses
- [Tmax/Rth] Use the rise above ambient.
- [any] $\frac{T_\text{max} - T_a}{R_\theta}$.
:::
:::
:::
