Tutorial 3: Derivatives, Graphing, and Optimization

Carleton College Math 111 01-02, Fall 2007
Prof. Joshua R. Davis

revised 2007 October 25, 12:30 PM

Reflection Of Light Off A Mirror

Suppose that a mirror is situated along the x-axis in the x-y-plane. A particle of light (called a photon) leaves (0, 1), travels in a straight line, bounces off the mirror at some point (x, 0), continues on along a straight line, and ends up at the point (1, 1). Here is a picture showing three possible light paths; one reflects at 0.2, one reflects at 0.5, and one reflects at 0.66....

Clear[x]
Show[Plot[-2 x + 1, {x, 0, 1/2}], Plot[2 x - 1, {x, 1/2, 1}], Plot[-5 x + 1, {x, 0, 1/5}], Plot[(5 / 4) x - 1 / 4, {x, 1/5, 1}], Plot[(-3 / 2) x + 1, {x, 0, 2 / 3}], Plot[3 x - 2, {x, 2 / 3, 1}], PlotRange -> {0, 1}]

Perhaps you already know, based on a physics class or your own personal experience, that in reality the only path that the light can take is the one that hits the x-axis at 0.5. That's because when light reflects the angles of incidence and reflection (the two acture angles that the light beam makes with the mirror) must be equal, and in this problem only the path that hits at 0.5 satisfies this condition. But why must the angles of incidence and reflection be equal? What is the fundamental physical reason for that fact?

It turns out that many phenomena of light can be explained using Fermat's principle of least time, which simply says that light travels between two points by the fastest possible path. This is why it travels in straight lines, when there is nothing in its way. The principle of least time also explains why the angles of incidence and reflection are equal. To see this, we need to find a function t(x) that gives the travel time of the particle of light if it bounces at (x, 0). Since time = distance/speed, the travel time is the distance from (0, 1) to (x, 0), plus the distance from (x, 0) to (1, 1), all divided by the speed of light -- a constant called c, which is about 300 (million meters per second).

Clear[x]
c = 300
t = (Sqrt[(x - 0)^2 + (0 - 1)^2] + Sqrt[(1 - x)^2 + (1 - 0)^2]) / c

The principle of least time says that we should figure out where the travel time t is minimized. To get an idea, let's plot t(x):

Plot[t, {x, -1, 2}]

From the graph, we see that the light beams that bounce at x = 0.2 and x = 0.66... take more time to reach (1, 1) than the one that bounces at x = 0.5. To see that the minimum time occurs at x = 0.5 more precisely, let's take the derivative:

dtdx = Simplify[D[t, x]]

On paper, you can do algebra until you discover that the solution to dtdx = 0 is x = 0.5. Or, if you're lazy, you can ask Mathematica to solve it for you:

Solve[dtdx == 0]

You should also take the second derivative and verify that it is positive at x = 0.5. Or you can make Mathematica do it:

d2tdx2 = Simplify[D[dtdx, x]]
d2tdx2 /. x -> 1/2

At this point we know for sure that x = 0.5 is a local minimum for travel time. And it's easy to see from the graph (or an algebraic argument) that all other x-values produce larger travel times. So travel time really is minimized when x = 0.5, and this is precisely the x needed to make the angles of incidence and reflection are equal. In this way Fermat's principle of least time predicts that, or explains why, the angles of incidence and reflection are equal.

The principle of least time also explains many other phenomena of light, such as Snells' law of refraction. In fact, almost all of physics (and hence almost all of science) can be explained by a modern version of Fermat's principle called the action principle. In modern physics (since the 1940s) the action principle is seen as a consequence of the even deeper physical concept of path integrals, but that is far beyond this course's scope.

Body Temperature Throughout A Menstrual Cycle

Here are data on how a woman's body temperature varies throughout her menstrual cycle, taken from 

        http://www-rohan.sdsu.edu/~jmahaffy/courses/f06/math121/index.html

On the horizontal axis are days since the start of the menstrual cycle, and on the vertical axis are body temperatures in degrees Celsius.

data = {{0, 36.4}, {1, 36.3}, {2, 36.1}, {3, 36.2}, {4, 36.2}, {5, 36.2}, {6, 36.3}, {7, 36.1}, {8, 36.0}, {9, 36.1}, {10, 36.1}, {11, 36.3}, {12, 36.4}, {13, 36.15}, {14, 36.25}, {15, 36.45}, {16, 36.5}, {17, 36.65}, {18, 36.6}, {19, 36.6}, {20, 36.7}, {21, 36.75}, {22, 36.7}, {23, 36.65}, {24, 36.7}, {25, 36.6}, {26, 36.55}, {27, 36.55}, {28, 36.4}}
dataPlot = ListPlot[data, PlotStyle -> PointSize[Large]]

One can fit a cubic polynomial to this data; the best cubic fit is

        y = -0.0002762 x^3 + 0.01175 x^2 - 0.1121 x + 36.41.

However, since the data are probably going to repeat after the 28th day (after all, the menstrual cycle is a "cycle"), it makes more sense to fit some sort of sinusoidal curve of the form

        y = a Sin[b x + c] + d.

The function y = Sin[x] has what period? So how much should we compress/stretch it horizontally, to get a period of 28? Which of the four unknown parameters a, b, c, d does this tell you? Figure this out before moving on.

It tells you that b = 2 Pi / 28. So let's plug that in and find the remaining parameters using Mathematica's FindFit function.

Clear[a, c, d, x]
function =  a Sin[(2 Pi / 28) x + c] + d
fitParameters = FindFit[data, function, {a, c, d}, x]
fitFunction = function /. fitParameters
curvePlot = Plot[fitFunction, {x, 0, 28}, PlotStyle -> Thick]
Show[dataPlot, curvePlot]

According to the fit curve, when is this woman's temperature greatest? When is it lowest? When is it increasing? Decreasing? To answer these questions, you study where the derivative is zero, positive, or negative.

The woman's fertility is greatest at the onset of ovulation, which occurs when body temperature is increasing the fastest. When is this? To answer this question, you wish to maximize the derivative. How would you do that? The derivative is maximized when its derivative (the second derivative of the original function) changes from positive to negative. That's at an inflection point. Solve this problem in detail, on paper, for yourself. You'll find that the inflection point is around day 14. So that's when ovulation occurs, and when fertility is greatest. This is something that a fertility counselor or any couple interesting in having a baby (or not having one) would want to know.

By the way, in previous tutorials we have always used the FindFit function to find linear fits (which we can then use to get power law and exponential fits). But you see here that it can work with a variety of functions. Whenever you use a complicated piece of software, you should always be curious as to how it works. So here is the rough idea. FindFit first sets up an "error function", depending on a, c, and d, that measures how bad the fit is for that choice of a, c, and d. The best possible fit, then, is the one that minimizes the error function.

So we see that fitting a curve to data ends up being a minimization problem, like the ones we study in calculus. It is a difficult minimization problem, depending on multiple variables, so it's beyond the level of Calculus I. But I should tell you that it's solved using an interative numerical method, not dissimilar to Newton's method. So the calculus we've been studying really is useful for real-world problems such as modeling the menstrual cycle.

Newscaster Popularity

Willoughby McWillowsalot is a venerable television newscaster. He started in the dead of winter in 1957, and he's been going ever since. Let p(t) be his popularity (in millions of viewers) at time t (in years since he began). It turns out that p(t) is roughly Sqrt[t], but it's about 100,000 viewers higher each winter and about 100,000 viewers lower each summer.

Can you imagine why Willoughby has fewer viewers in summer than in winter?

To get an explicit formula for p(t), we start with Sqrt[t] and then add on a sinusoidal function with an amplitude of 0.1 (million viewers) and a period of 1 (year). We should use the cosine function, since this has a crest at t = 0, which corresponds to the initial boost of popularity in the winter of 1957. How much should we horizontally compress cosine, to make it have a period of 1? Make sure you understand how I chose this function p:

Clear[t]
p = Sqrt[t] + 0.1 Cos[2 Pi t]
popularityPlot = Plot[p, {t, 0, 50}, PlotStyle -> Thick]

On my computer, Mathematica doesn't graph that function very well. Is the same true on yours? What's wrong with it? Can you imagine what Mathematica is doing wrong?

Mathematica graphs by plotting points and connecting those points with lines. If the points that it chooses all happen to fall at the troughs of a cosine curve, then it connects those troughs and we miss the oscillation entirely. To fix this, add a PlotPoints option telling Mathematica to use some large number of points, such as 200.

popularityPlot = Plot[p, {t, 0, 50}, PlotStyle -> Thick,PlotPoints->200]

v = D[p, t]
a = D[v, t]
velocityPlot = Plot[v, {t, 0, 50}, PlotStyle -> Thick,PlotPoints->200]
accelerationPlot = Plot[a, {t, 0, 50}, PlotStyle -> Thick,PlotPoints->200]

Maybe Mathematica's Solve or NSolve function can figure out where the second derivative is zero? No, they can't. I don't know why.

Solve[a == 0, t]
NSolve[a == 0, t]

But the FindRoot function can figure it out. This function is much like Solve or NSolve, but it takes in a seed value. Based on a plot of the acceleration, I'll choose a seed value of 0.1.

FindRoot[a, {t, 0.1}]

What root-finding method have we studied that uses a seed value? Newton's method, right? The implementation notes at

        http://reference.wolfram.com/mathematica/note/SomeNotesOnInternalImplementation.html#2118

indicate that FindRoot uses a version of Newton's method, at least sometimes.

Marginality

Did you know that I own a company that makes spaceships? I do. Suppose that my company makes q spaceships. The cost of making q spaceships is some function C(q). (In this problem, monetary figures are always in millions of dollars.) Revenue means income; it is the amount of money that I pull in from selling spaceships. It is also some function R(q). Profit means net income; it is the revenue minus the cost. So the profit function P(q) is given by P(q) = R(q) - C(q).

A basic question to ask is, "Am I making the right number of spaceships? Should I make more?" I should make more as long as my profit function is going up, so as long as P'(q) = R'(q) - C'(q) > 0. I should stop making spaceships when I've made q such that P'(q) = R'(q) - C'(q) = 0. The quantities R'(q) and C'(q) are called marginal revenue and marginal cost; what we have learned is that when profit is maximized, marginal revenue equals marginal cost.

Let S(q) be the sale price, per spaceship, when I've made q spaceships. Do you think that S(q) is increasing or decreasing?

How does R(q) relate to S(q)?

Perhaps C(q) = m q + b. Why would this be? In practical terms, what are m and b?

Suppose that C(q) = 10000 + 100 q and S(q) = 1000 q^(-1/2). How many spaceships should I make?