```
using CalculusWithJulia
using Plots
plotly()
using Roots
using SymPy
```

# 34 Related rates

This section uses these add-on packages:

Related rates problems involve two (or more) unknown quantities that are related through an equation. As the two variables depend on each other, also so do their rates - change with respect to some variable which is often time, though exactly how remains to be discovered. Hence the name “related rates.”

#### Examples

The following is a typical “book” problem:

A screen saver displays the outline of a \(3\) cm by \(2\) cm rectangle and then expands the rectangle in such a way that the \(2\) cm side is expanding at the rate of \(4\) cm/sec and the proportions of the rectangle never change. How fast is the area of the rectangle increasing when its dimensions are \(12\) cm by \(8\) cm? Source.

Here we know \(A = w \cdot h\) and we know some things about how \(w\) and \(h\) are related *and* about the rate of how both \(w\) and \(h\) grow in time \(t\). That means that we could express this growth in terms of some functions \(w(t)\) and \(h(t)\), then we can figure out that the area - as a function of \(t\) - will be expressed as:

\[ A(t) = w(t) \cdot h(t). \]

We would get by the product rule that the *rate of change* of area with respect to time, \(A'(t)\) is just:

\[ A'(t) = w'(t) h(t) + w(t) h'(t). \]

As an aside, it is fairly conventional to suppress the \((t)\) part of the notation \(A=wh\) and to use the Leibniz notation for derivatives:

\[ \frac{dA}{dt} = \frac{dw}{dt} h + w \frac{dh}{dt}. \]

This relationship is true for all \(t\), but the problem discusses a certain value of \(t\) - when \(w(t)=8\) and \(h(t) = 12\). At this same value of \(t\), we have \(w'(t) = 4\) and so \(h'(t) = 6\). Substituting these 4 values into the 4 unknowns in the formula for \(A'(t)\) gives:

\[ A'(t) = 4 \cdot 12 + 8 \cdot 6 = 96. \]

Summarizing, from the relationship between \(A\), \(w\) and \(t\), there is a relationship between their rates of growth with respect to \(t\), a time variable. Using this and known values, we can compute. In this case, \(A'\) at the specific \(t\).

We could also have done this differently. We would recognize the following:

- The area of a rectangle is just:

`A(w,h) = w * h`

`A (generic function with 1 method)`

- The width - expanding at a rate of \(4t\) from a starting value of \(2\) - must satisfy:

`w(t) = 2 + 4*t`

`w (generic function with 1 method)`

- The height is a constant proportion of the width:

`h(t) = 3/2 * w(t)`

`h (generic function with 1 method)`

This means again that area depends on \(t\) through this formula:

`A(t) = A(w(t), h(t))`

`A (generic function with 2 methods)`

This is why the rates of change are related: as \(w\) and \(h\) change in time, the functional relationship with \(A\) means \(A\) also changes in time.

Now to answer the question, when the width is 8, we must have that \(t\) is:

`= find_zero(x -> w(x) - 8, [0, 4]) # or solve by hand to get 3/2 tstar `

`1.5`

The question is to find the rate the area is increasing at the given time \(t\), which is \(A'(t)\) or \(dA/dt\). We get this by performing the differentiation, then substituting in the value.

Here we do so with the aid of `Julia`

, though this problem could readily be done “by hand.”

We have expressed \(A\) as a function of \(t\) by composition, so can differentiate that:

`'(tstar) A`

`96.0`

Now what? Why is \(96\) of any interest? It is if the value at a specific time is needed. But in general, a better question might be to understand if there is some pattern to the numbers in the figure, these being \(6, 54, 150, 294, 486, 726\). Their differences are the *average* rate of change:

```
= [6, 54, 150, 294, 486, 726]
xs = diff(xs) ds
```

```
5-element Vector{Int64}:
48
96
144
192
240
```

Those seem to be increasing by a fixed amount each time, which we can see by one more application of `diff`

:

`diff(ds)`

```
4-element Vector{Int64}:
48
48
48
48
```

How can this relationship be summarized? Well, let’s go back to what we know, though this time using symbolic math:

```
@syms t
diff(A(t), t)
```

\(48.0 t + 24.0\)

This should be clear: the rate of change, \(dA/dt\), is increasing linearly, hence the second derivative, \(d^2A/dt^2\) would be constant, just as we saw for the average rate of change.

So, for this problem, a constant rate of change in width and height leads to a linear rate of change in area, put otherwise, linear growth in both width and height leads to quadratic growth in area.

##### Example

A ladder, with length \(l\), is leaning against a wall. We parameterize this problem so that the top of the ladder is at \((0,h)\) and the bottom at \((b, 0)\). Then \(l^2 = h^2 + b^2\) is a constant.

If the ladder starts to slip away at the base, but remains in contact with the wall, express the rate of change of \(h\) with respect to \(t\) in terms of \(db/dt\).

We have from implicitly differentiating in \(t\) the equation \(l^2 = h^2 + b^2\), noting that \(l\) is a constant, that:

\[ 0 = 2h \frac{dh}{dt} + 2b \frac{db}{dt}. \]

Solving, yields:

\[ \frac{dh}{dt} = -\frac{b}{h} \cdot \frac{db}{dt}. \]

- If when \(l = 12\) it is known that \(db/dt = 2\) when \(b=4\), find \(dh/dt\).

We just need to find \(h\) for this value of \(b\), as the other two quantities in the last equation are known.

But \(h = \sqrt{l^2 - b^2}\), so the answer is:

```
= 12, 4, 2
length, bottom, dbdt = sqrt(length^2 - bottom^2)
height -bottom/height * dbdt
```

`-0.7071067811865475`

- What happens to the rate as \(b\) goes to \(l\)?

As \(b\) goes to \(l\), \(h\) goes to \(0\), so \(b/h\) blows up. Unless \(db/dt\) goes to \(0\), the expression will become \(-\infty\).

Often, this problem is presented with \(db/dt\) having a constant rate. In this case, the ladder problem defies physics, as \(dh/dt\) eventually is faster than the speed of light as \(h \rightarrow 0+\). In practice, were \(db/dt\) kept at a constant, the ladder would necessarily come away from the wall. The trajectory would follow that of a tractrix were there no gravity to account for.

##### Example

Shadows are a staple of film noir. In the photo, suppose a man and a woman walk towards a street light. As they approach the light the length of their shadow changes.

Suppose, we focus on the \(5\) foot tall woman. Her shadow comes from a streetlight \(12\) feet high. She is walking at \(3\) feet per second towards the light. What is the rate of change of her shadow?

The setup for this problem involves drawing a right triangle with height \(12\) and base given by the distance \(x\) from the light the woman is *plus* the length \(l\) of the shadow. There is a similar triangle formed by the woman’s height with length \(l\). Equating the ratios of the sided gives:

\[ \frac{5}{l} = \frac{12}{x + l} \]

As we need to take derivatives, we work with the reciprocal relationship:

\[ \frac{l}{5} = \frac{x + l}{12} \]

Differentiating in \(t\) gives:

\[ \frac{l'}{5} = \frac{x' + l'}{12} \]

Or

\[ l' \cdot (\frac{1}{5} - \frac{1}{12}) = \frac{x'}{12} \]

Solving for \(l'\) gives an answer in terms of \(x'\) the rate the woman is walking. In this description \(x\) is getting shorter, so \(x'\) would be \(-3\) feet per second and the shadow length would be decreasing at a rate proportional to the walking speed.

##### Example

The sun is setting at the rate of \(1/20\) radian/min, and appears to be dropping perpendicular to the horizon, as depicted in the figure. How fast is the shadow of a \(25\) meter wall lengthening at the moment when the shadow is \(25\) meters long?

Let the shadow length be labeled \(x\), as it appears on the \(x\) axis above. Then we have by right-angle trigonometry:

\[ \tan(\theta) = \frac{25}{x} \]

of \(x\tan(\theta) = 25\).

As \(t\) evolves, we know \(d\theta/dt\) but what is \(dx/dt\)? Using implicit differentiation yields:

\[ \frac{dx}{dt} \cdot \tan(\theta) + x \cdot (\sec^2(\theta)\cdot \frac{d\theta}{dt}) = 0 \]

Substituting known values and identifying \(\theta=\pi/4\) when the shadow length, \(x\), is \(25\) gives:

\[ \frac{dx}{dt} \cdot \tan(\pi/4) + 25 \cdot(4/2) \cdot \frac{-1}{20} = 0 \]

This can be solved for the unknown: \(dx/dt = 50/20\).

##### Example

A batter hits a ball toward third base at \(75\) ft/sec and runs toward first base at a rate of \(24\) ft/sec. At what rate does the distance between the ball and the batter change when \(2\) seconds have passed?

We will answer this with `SymPy`

. First we create some symbols for the movement of the ball towards third base, `b(t)`

, the runner toward first base, `r(t)`

, and the two velocities. We use symbolic functions for the movements, as we will be differentiating them in time:

```
@syms b() r() v_b v_r
= sqrt(b(t)^2 + r(t)^2) d
```

\(\sqrt{b^{2}{\left(t \right)} + r^{2}{\left(t \right)}}\)

The distance formula applies to give \(d\). As the ball and runner are moving in a perpendicular direction, the formula is easy to apply.

We can differentiate `d`

in terms of `t`

and in process we also find the derivatives of `b`

and `r`

:

```
= diff(b(t),t), diff(r(t),t) # b(t), r(t) -- symbolic functions
db, dr = diff(d,t) # d -- not d(t) -- an expression dd
```

\(\frac{b{\left(t \right)} \frac{d}{d t} b{\left(t \right)} + r{\left(t \right)} \frac{d}{d t} r{\left(t \right)}}{\sqrt{b^{2}{\left(t \right)} + r^{2}{\left(t \right)}}}\)

The slight difference in the commands is due to `b`

and `r`

being symbolic functions, whereas `d`

is a symbolic expression. Now we begin substituting. First, from the problem `db`

is just the velocity in the ball’s direction, or `v_b`

. Similarly for `v_r`

:

`= subs(dd, db => v_b, dr => v_r) ddt `

\(\frac{v_{b} b{\left(t \right)} + v_{r} r{\left(t \right)}}{\sqrt{b^{2}{\left(t \right)} + r^{2}{\left(t \right)}}}\)

Now, we can substitute in for `b(t)`

, as it is `v_b*t`

, etc.:

`= subs(ddt, b(t) => v_b * t, r(t) => v_r * t) ddt₁ `

\(\frac{t v_{b}^{2} + t v_{r}^{2}}{\sqrt{t^{2} v_{b}^{2} + t^{2} v_{r}^{2}}}\)

This finds the rate of change of time for any `t`

with symbolic values of the velocities. (And shows how the answer doesn’t actually depend on \(t\).) The problem’s answer comes from a last substitution:

`ddt₁(t => 2, v_b => 75, v_r => 24)`

\(3 \sqrt{689}\)

Were this done by “hand,” it would be better to work with distance squared to avoid the expansion of complexity from the square root. That is, using implicit differentiation:

\[ \begin{align*} d^2 &= b^2 + r^2\\ 2d\cdot d' &= 2b\cdot b' + 2r\cdot r'\\ d' &= (b\cdot b' + r \cdot r')/d\\ d' &= (tb'\cdot b' + tr' \cdot r')/d\\ d' &= \left((b')^2 + (r')^2\right) \cdot \frac{t}{d}. \end{align*} \]

##### Example

A baseball player stands \(100\) meters from home base. A batter hits the ball directly at the player so that the distance from home plate is \(x(t)\) and the height is \(y(t)\).

The player tracks the flight of the ball in terms of the angle \(\theta\) made between the ball and the player. This will satisfy:

\[ \tan(\theta) = \frac{y(t)}{100 - x(t)}. \]

What is the rate of change of \(\theta\) with respect to \(t\) in terms of that of \(x\) and \(y\)?

We have by the chain rule and quotient rule:

\[ \sec^2(\theta) \theta'(t) = \frac{y'(t) \cdot (100 - x(t)) - y(t) \cdot (-x'(t))}{(100 - x(t))^2}. \]

If we have \(x(t) = 50t\) and \(y(t)=v_{0y} t - 5 t^2\) when is the rate of change of the angle happening most quickly?

The formula for \(\theta'(t)\) is

\[ \theta'(t) = \cos^2(\theta) \cdot \frac{y'(t) \cdot (100 - x(t)) - y(t) \cdot (-x'(t))}{(100 - x(t))^2}. \]

This question requires us to differentiate *again* in \(t\). Since we have fairly explicit function for \(x\) and \(y\), we will use `SymPy`

to do this.

```
@syms theta()
= 5
v0 x(t) = 50t
y(t) = v0*t - 5 * t^2
= tan(theta(t)) - y(t) / (100 - x(t)) eqn
```

\(\tan{\left(\theta{\left(t \right)} \right)} - \frac{- 5 t^{2} + 5 t}{100 - 50 t}\)

```
= diff(theta(t),t)
thetap = solve(diff(eqn, t), thetap)[1] dtheta
```

\(\frac{\left(- t^{3} + 3 t^{2} + 2 t \left(t - 2\right)^{2} - 2 t - \left(t - 2\right)^{2}\right) \cos^{2}{\left(\theta{\left(t \right)} \right)}}{10 \left(t - 2\right)^{3}}\)

We could proceed directly by evaluating:

`= diff(dtheta, t)(thetap => dtheta) d2theta `

\(\frac{\left(- 3 t^{2} + 2 t \left(2 t - 4\right) + 4 t + 2 \left(t - 2\right)^{2} + 2\right) \cos^{2}{\left(\theta{\left(t \right)} \right)}}{10 \left(t - 2\right)^{3}} - \frac{3 \left(- t^{3} + 3 t^{2} + 2 t \left(t - 2\right)^{2} - 2 t - \left(t - 2\right)^{2}\right) \cos^{2}{\left(\theta{\left(t \right)} \right)}}{10 \left(t - 2\right)^{4}} - \frac{\left(- t^{3} + 3 t^{2} + 2 t \left(t - 2\right)^{2} - 2 t - \left(t - 2\right)^{2}\right)^{2} \sin{\left(\theta{\left(t \right)} \right)} \cos^{3}{\left(\theta{\left(t \right)} \right)}}{50 \left(t - 2\right)^{6}}\)

That is not so tractable, however.

It helps to simplify \(\cos^2(\theta(t))\) using basic right-triangle trigonometry. Recall, \(\theta\) comes from a right triangle with height \(y(t)\) and length \((100 - x(t))\). The cosine of this angle will be \(100 - x(t)\) divided by the length of the hypotenuse. So we can substitute:

`= dtheta(cos(theta(t))^2 => (100 -x(t))^2/(y(t)^2 + (100-x(t))^2)) dtheta₁ `

\(\frac{\left(100 - 50 t\right)^{2} \left(- t^{3} + 3 t^{2} + 2 t \left(t - 2\right)^{2} - 2 t - \left(t - 2\right)^{2}\right)}{10 \left(t - 2\right)^{3} \left(\left(100 - 50 t\right)^{2} + \left(- 5 t^{2} + 5 t\right)^{2}\right)}\)

Plotting reveals some interesting things. For \(v_{0y} < 10\) we have graphs that look like:

`plot(dtheta₁, 0, v0/5)`

The ball will drop in front of the player, and the change in \(d\theta/dt\) is monotonic.

But let’s rerun the code with \(v_{0y} > 10\):

```
= 15
v0 x(t) = 50t
y(t) = v0*t - 5 * t^2
= tan(theta(t)) - y(t) / (100 - x(t))
eqn = diff(theta(t),t)
thetap = solve(diff(eqn, t), thetap)[1]
dtheta = subs(dtheta, cos(theta(t))^2, (100 - x(t))^2/(y(t)^2 + (100 - x(t))^2))
dtheta₁ plot(dtheta₁, 0, v0/5)
```

In the second case we have a different shape. The graph is not monotonic, and before the peak there is an inflection point. Without thinking too hard, we can see that the greatest change in the angle is when it is just above the head (\(t=2\) has \(x(t)=100\)).

That these two graphs differ so, means that the player may be able to read if the ball is going to go over his or her head by paying attention to how the ball is being tracked.

##### Example

Hipster pour-over coffee is made with a conical coffee filter. The cone is actually a frustum of a cone with small diameter, say \(r_0\), chopped off. We will parameterize our cone by a value \(h \geq 0\) on the \(y\) axis and an angle \(\theta\) formed by a side and the \(y\) axis. Then the coffee filter is the part of the cone between some \(h_0\) (related \(r_0=h_0 \tan(\theta)\)) and \(h\).

The volume of a cone of height \(h\) is \(V(h) = \pi/3 h \cdot R^2\). From the geometry, \(R = h\tan(\theta)\). The volume of the filter then is:

\[ V = V(h) - V(h_0). \]

What is \(dV/dh\) in terms of \(dR/dh\)?

Differentiating implicitly gives:

\[ \frac{dV}{dh} = \frac{\pi}{3} ( R(h)^2 + h \cdot 2 R \frac{dR}{dh}). \]

We see that it depends on \(R\) and the change in \(R\) with respect to \(h\). However, we visualize \(h\) - the height - so it is better to re-express. Clearly, \(dR/dh = \tan\theta\) and using \(R(h) = h \tan(\theta)\) we get:

\[ \frac{dV}{dh} = \pi h^2 \tan^2(\theta). \]

The rate of change goes down as \(h\) gets smaller (\(h \geq h_0\)) and gets bigger for bigger \(\theta\).

How do the quantities vary in time?

For an incompressible fluid, by balancing the volume leaving with how it leaves we will have \(dh/dt\) is the ratio of the cross-sectional area at bottom over that at the height of the fluid \((\pi \cdot (h_0\tan(\theta))^2) / (\pi \cdot ((h\tan\theta))^2)\) times the outward velocity of the fluid.

That is \(dh/dt = (h_0/h)^2 \cdot v\). Which makes sense - larger openings (\(h_0\)) mean more fluid lost per unit time so the height change follows, higher levels (\(h\)) means the change in height is slower, as the cross-sections have more volume.

By Torricelli’s law, the out velocity follows the law \(v = \sqrt{2g(h-h_0)}\). This gives:

\[ \frac{dh}{dt} = \frac{h_0^2}{h^2} \cdot v = \frac{h_0^2}{h^2} \sqrt{2g(h-h_0)}. \]

If \(h >> h_0\), then \(\sqrt{h-h_0} = \sqrt{h}\sqrt{(1 - h_0/h)} \approx \sqrt{h}(1 - (1/2)(h_0/h)) \approx \sqrt{h}\). So the rate of change of height in time is like \(1/h^{3/2}\).

Now, by the chain rule, we have then the rate of change of volume with respect to time, \(dV/dt\), is:

\[ \begin{align*} \frac{dV}{dt} &= \frac{dV}{dh} \cdot \frac{dh}{dt}\\ &= \pi h^2 \tan^2(\theta) \cdot \frac{h_0^2}{h^2} \sqrt{2g(h-h_0)} \\ &= \pi \sqrt{2g} \cdot (r_0)^2 \cdot \sqrt{h-h_0} \\ &\approx \pi \sqrt{2g} \cdot r_0^2 \cdot \sqrt{h}. \end{align*} \]

This rate depends on the square of the size of the opening (\(r_0^2\)) and the square root of the height (\(h\)), but not the angle of the cone.

## 34.1 Questions

###### Question

Supply and demand. Suppose demand for product \(XYZ\) is \(d(x)\) and supply is \(s(x)\). The excess demand is \(d(x) - s(x)\). Suppose this is positive. How does this influence price? Guess the “law” of economics that applies:

(Theoretically, when demand exceeds supply, prices increase.)

###### Question

Which makes more sense from an economic viewpoint?

(Colloquially, “the rate of change of unemployment is negative” means the unemployment rate is going down, so there are fewer workers available to fill new jobs.)

###### Question

In chemistry there is a fundamental relationship between pressure (\(P\)), temperature (\(T)\) and volume (\(V\)) given by \(PV=cT\) where \(c\) is a constant. Which of the following would be true with respect to time?

###### Question

A pebble is thrown into a lake causing ripples to form expanding circles. Suppose one of the circles expands at a rate of \(1\) foot per second and the radius of the circle is \(10\) feet, what is the rate of change of the area enclosed by the circle?

###### Question

A pizza maker tosses some dough in the air. The dough is formed in a circle with radius \(10\). As it rotates, its area increases at a rate of \(1\) inch\(^2\) per second. What is the rate of change of the radius?

###### Question

An FBI agent with a powerful spyglass is located in a boat anchored 400 meters offshore. A gangster under surveillance is driving along the shore. Assume the shoreline is straight and that the gangster is 1 km from the point on the shore nearest to the boat. If the spyglasses must rotate at a rate of \(\pi/4\) radians per minute to track the gangster, how fast is the gangster moving? (In kilometers per minute.) Source.

###### Question

A flood lamp is installed on the ground 200 feet from a vertical wall. A six foot tall man is walking towards the wall at the rate of 4 feet per second. How fast is the tip of his shadow moving down the wall when he is 50 feet from the wall? Source. (As the question is written the answer should be positive.)

###### Question

Consider the hyperbola \(y = 1/x\) and think of it as a slide. A particle slides along the hyperbola so that its x-coordinate is increasing at a rate of \(f(x)\) units/sec. If its \(y\)-coordinate is decreasing at a constant rate of \(1\) unit/sec, what is \(f(x)\)? Source.

###### Question

A balloon is in the shape of a sphere, fortunately, as this gives a known formula, \(V=4/3 \pi r^3\), for the volume. If the balloon is being filled with a rate of change of volume per unit time is \(2\) and the radius is \(3\), what is rate of change of radius per unit time?

###### Question

Consider the curve \(f(x) = x^2 - \log(x)\). For a given \(x\), the tangent line intersects the \(y\) axis. Where?

If \(dx/dt = -1\), what is \(dy/dt\)?