Lab Two - Derivatives, Linear approximations, and Modeling

Derivatives, linear approximations (tangent lines), and some modeling of data with exponential and/or log functions.

Andy Long, MAT229, Spring 2025

Defining (e^x) and ln(x)

We’ll start by defining the important functions we’ll be using here today: exponentials and logs. 

Since we’re used to calling them by the names e(x) and ln(x), let’s define those functions by essentially “aliasing” the built-in Mathematica functions of Exp and Log.

e[x_]:=Exp[x]
ln[x_]:=Log[x]
e[1.0]
ln[1.0]

Having defined them, we’re going to want to plot them, as we did yesterday by hand. So much nicer when we allow Mathematica to do it for us...:) Here’s my version, which I hope that you can reproduce.

Let’s plot them both, along with the “mirror” of y=x. We’ll use the command “Plot”, and a few options:
	1. AspectRatio (I used the value 1)
	2. PlotRange (if you make just one list, e.g. {-4,8}, it refers to the y-axis; a list of two lists and it will assume that the first is for the x-axis, and the second for the y-axis). 
	3. PlotStyle (with color or dashed or size options, which can be lists of several options)

If we define a variable (let’s call it “plots”) as the result of the Plot command, we can use it later with the Show command to layer several plots together into one nice graphic, which we’ll do once we have this one.

Now we’re going to add in some tangent lines, and a couple of points at which we want to draw those tangents.

plots=Plot[{ln[x],e[x],x},{x,-4,8},AspectRatio->1,PlotRange->{-4,8},PlotStyle->{Blue,Black,Dashed}]

Let’s define two functions, the linear functions whose graphs are the tangent lines at a point (a,b)=(2,ln(2)) on the graph of ln, and the point (ln(2),2) on the graph of e^x. I called them

tangentE[x]
tangentL[x]

Defining constants is easy, by the way, e.g.
a=2;

And the derivatives work in the usual way: we can use e’[x] and ln’[x] for the derivatives, and ask for a particular value of the derivative at a given point, e.g. e’[2], or ln’[a].

To add the points, we’ll use “ListPlot”, and also use the PlotStyle option to set the PointSize to Large:

a=2;
b=Log[2];
tangentE[x_]:=a+e'[b](x-b);
tangentL[x_]:=b+ln'[a](x-a);

Show[
plots,
ListPlot[{{a,b},{b,a}},PlotStyle->{PointSize[Large]}],
Plot[{tangentE[x],tangentL[x]},{x,-4,8},PlotStyle->{{Blue,Dashed},{Black,Dashed}}]
]

Let’s use the Manipulate command to show how the tangent lines vary together as we vary the value of a (and hence b) in the graph above.d

Manipulate[
b=Log[a];
tangentE[x_]:=a+e'[b](x-b);
tangentL[x_]:=b+ln'[a](x-a);
Show[
plots,
ListPlot[{{a,b},{b,a}},PlotStyle->{PointSize[Large]}],
Plot[{tangentE[x],tangentL[x]},{x,-4,8},PlotStyle->{{Blue,Dashed},{Black,Dashed}}]
],
{a,0.08,8}
]

That function x^x....

g[x_]:=x^x
g'[x]
Plot[{g[x],g'[x]},{x,-2,2},AspectRatio->1,PlotRange->{-2,2},PlotStyle->{Blue,Black}]

We talked about the function x^x yesterday, and found a way to differentiate it (using logarithmic differentiation. Here’s a plot of that pair of functions:

Can you generate this plot?

Finally a couple of modeling exercises:

Exercise 359 : population of Toledo, OH.

The population of Toledo, Ohio, in 2000 was approximately 500,000. Assume the population is increasing at a rate of 5% per year. 
	a. Write the exponential function that relates the total population as a function of time t.
	b. Use a. to determine the rate at which the population is increasing in t years.
	c. Use b. to determine the rate at which the population is increasing in 10 years.

Exercise 363:

For the following exercises, use the population of New York City from 1790 to 1860, given in the following table.
0 	33,131
10 	60,515
20 	96,373
30 	123,706
40 	202,300
50 	312,710
60 	515,547
70 	813,669

Using a computer program or a calculator, fit a growth curve to the data of the form p(t)=a(b^t)

I’ll show you one way that you can enter the data (saving you some time, but check out the structure):

xs=10*Table[i,{i,0,7}];
ys={33131,60515,  96373, 123706, 202300, 312710, 515547, 813669};

This is the exact same command as we used in the modeling exercise from Lab 01, although I’ve added the PlotStyle command so that we can see the dots more easily:

dataPlot=ListPlot[Transpose[{xs,ys}],PlotStyle->PointSize[Large]];

Finally the Manipulate command, which gives us the opportunity to create a reasonable model:

Manipulate[
Show[
Plot[ a  b^x ,{x,0,70},PlotRange->{0,900000},PlotLabel->a  b^x ],
dataPlot
], (* Here's the Show command we'll execute each time *)
{a,20000,800000}, (* There are these two parameters which are going to change each time*)
{b,1.001,1.1,.001}
]

Exercise 366:

a. Will the model (of Exercise 363) be accurate in predicting the future population of New York City? Why or why not?
 b. Estimate the population in 2010. Was the prediction correct from a.?