Math 166
 Computer Lab # 3
 Exponential Growth and Decay

Goal: To use Mathematica  to investigate problems which involve exponential growth or decay.

New Mathematica  commands introduced:  FindRoot

Introduction

One of the most important ways the exponential function occurs in applications in science and engineering is in the solution to exponential growth and decay laws.  In many instances we can make the assumption that the rate of change of a quantity is proportional to the current amount.  This statement can be formulated in mathematical terms as an ordinary differential equation.  For y=y(t) we have

y'(t) = dy/dt = k y(t)   where k is a constant.

This differential equation states that the rate of change of y(t) is proportional to y(t) itself.  To solve this differential equation we must find a function y(t) whose derivative is k times itself.  For example, if k=1 then we seek a function whose derivative is itself and thus a particular solution is y(t)=et.  In class we obtained the general solution of the differential equation  y'(t)=k y(t)   by the technique of separation of variables. We obtained
         y(t) = Cekt  for some constant C. 
Also, if we impose the initial condition  y(0)= y0 then 
      y0 = y(0)=Ce0 implies C=y0.
Summarizing we have

The solution to 
                 dy/dt = k y(t)   
                  y(0) = y0
is given by
                  y(t) = y0 ekt .

If k>0 then we have exponential growth and if k<0 we have exponential decay.  This is shown in the graphs below.

p1=Plot[.5 E^(2t), {t,0,2},DisplayFunction->Identity,
PlotLabel->"Exponential Growth",PlotStyle->
RGBColor[1.000, 0.090, 0.118]]
p2=Plot[.5 E^(-2t), {t,0,2},DisplayFunction->Identity,
PlotLabel->"Exponential Decay",PlotStyle->
RGBColor[1.000, 0.090, 0.118]]
Show[GraphicsArray[{p1,p2},
DisplayFunction->$DisplayFunction]]

Applications

Model for the Spread of Diseases

One model for the way diseases spread assumes that the rate dP/dt at which the number of infected people, P(t), changes is proportional to the number P itself, i.e., dP/dt = k P for some constant k.  We know that the solution to this differential equation is
      P(t)=P0 ekt  where P(0) = P0.
      
Example 1.  Suppose that we know that in any given year the number of infected people P is reduced by 15%. (Thus our equation should model exponential decay.)  If it is estimated that there are 100,000 infected people today, how many infected people will there be in 2 years?  How many years will it take to reduce the number of infected people to 50,000?  Plot P(t) from t=0 to t=25.

At t=0, P =100,000 so 100,000= P0e0 or P0=100,000.  Thus we know that the number of infected people at any time t can be given by the expression:

Clear[p]
p[t_]:=100000 E^(k*t)

To solve for k we use the fact that after 1 year, the number of infected people, P, is reduced by 15%, i.e., 85,000 infected people remain after 1 year.  Thus  P(1)=85,000=100,000 ek1 .  Simplifying and taking the natural log of both sides gives

k=Log[.85]
p[t]

Note here that k<0 so that we have exponential decay.  

Instead of taking the natural log of both sides, we could have asked Mathematica to solve the equation 85=100 ek.  In this case, the Solve command will not work because it is mainly applicable for equations in which a closed form solution is known such as a quadratic or cubic equation; however, we can use the  FindRoot command.  We use this command in a similar way to Solve except we must give an initial guess for the value we are solving for.  This is because FindRoot  uses   Newton's method to find one  root (usually nearest your guess) and Solve is using a formula (such as the quadratic formula) and gives you all  solutions.  (If you use FindRoot and get a message back which states that Newton's method failed to converge, then try another initial guess.)  In our case, we know that we should have exponential decay, i.e., k<0, so we choose a small negative number for the initial guess.  

We first use the online help to find the correct syntax for the command FindRoot.  Note that as in the Solve command, we must use  ==  in our equation; in addition, the variable we are solving for and its initial guess are put in a list following the equation.

?FindRoot

Clear[k]
FindRoot[85==100 E^k, {k,-.1}]

Note that the output of the command FindRoot (and similarly for Solve) does not set k=-.0162519 but rather creates a transformation rule, i.e., k -> -.162519.  To set k to the value you can simply type k=-.162519  If you don't want to retype the value, open the following cell to see a more sophisticated way to to do it.

We can also set k= k replaced with (\. command) the value from the result of the FindRoot command.  If we use the % symbol to represent the output of the previous command we simply type 
    k = k \. %

Clear[k]
FindRoot[85==100 E^k, {k,-.1}]
k= k /. %
p[t]

Clear[k]
FindRoot[85==100 E^k, {k,-.1}]
k 
k=-.162519
p[t]

We now have an expression for the number of infected people, p[t], at any year past the initial year when P=100,000.  In particular, we can evaluate p[t] at any time t and plot it.

p[2]

Plot[p[t],{t,0,25},PlotLabel->"Exponential
Decay for Eradication 
of a Disease",PlotStyle->RGBColor[1.000, 0.090, 0.118]]

We now want to find the number of years it will take to reduce the number of infected people to 50,000.  We do this by solving the equation 50,000=P(t)  for t where P(t) is given above.  This can be done by taking the natural log of both sides of the equation or simply using the command FindRoot. From our plot above we see that we can use t=5 as an initial guess.

FindRoot[50000==p[t],{t,5}]

Thus it takes approximately 4 years and 3 months to reduce the number of infected people to 50,000.

Exercise 1.  In the above example, how long does it take to reduce the number of infected people to 10,000?

In this case we want to solve the equation P(t)=10,000 where P(t) is given above.  From the graph we can use t=15 as an initial guess for the FindRoot command.

FindRoot[10000==p[t],{t,15}]

Thus it takes approximately 14  years and 2 months to reduce the number of infected people to 10,000, i.e., to one-tenth the original number.

Consumer Price Index

The Consumer Price Index (CPI) is a way economists measure the cost of living.  This index is a weighted average of the costs of food, housing, transportation, medical costs, clothing, personal care, and entertainment.  The current index, set at 100 (an arbitrary choice for convenience) in 1984, was 112.1 in March of 1987 which loosely means that what you could buy for $1.00 in 1984 costs $1.12 in 1987.   One of the predictors of price change assumes that the rate dc/dt at which the CPI changes is proportional to the CPI, c, that is, dc/dt=k*c(t).  The constant k is called the continuous rate of inflation which is usually given as a percent, i.e., k=.03 implies a 3% rate of inflation.  Once again we have that the solution of the differential equation is given by
         c(t) = c0 ekt .
         
Example 2. Use the assumption that the CPI was set to 100 in 1984 and was 112.1 in 1987 and  assume k is a constant rate of inflation.  What do you expect the CPI to be in 1994?

If we begin measuring from 1984, we have that c(0)=100 since at time t=0 (1984) the CPI was set to 100.  By using the fact that in 1987 it had increased to 112.1, we can solve for k by solving the equation 
                  112.1=c(3)=100 e(3k) 
which we can solve by taking natural log of both sides (or alternately using the FindRoot command where we have used a positive initial guess since we know that we have exponential growth, i.e., k>0)

Clear[c,k]
c[t_]:=100 E^(k*t)
FindRoot[112.1==c[3],{k,.1}]

k=.0380737
c[t]

We now have an expression for the CPI at any year after 1984.  In particular,

c[10]

Thus in 1994, 10 years after t=0, we have that the CPI is given by
146.336; that is, what you could buy for $1.00 in 1984 now costs $1.46.

Exercise 2.  Assume the CPI in 1987 was 112.1 as in the previous example; however, we now assume that  beginning in 1987 the rate of inflation, k, is  a constant rate of 4.6%  instead of the value of 3.8% in Example 3.  Under these assumptions, what is the expected CPI in 1994?

Clear[c]
c[t_]:=112.1 E^(.046*t)
c[7]

Problems (to be handed in)

1.  Population growth is often modeled by exponential growth.  The reason for this is that populations usually grow faster as they get bigger because there are more people to reproduce.  One country which has had a very rapid growth rate is Mexico.  In 1980 the population was estimated to be 67.38 million and in 1982 it was estimated to be 70.93 million.  

Assuming that the population grows proportional to the current population, use the data given to predict the population of Mexico in 1993. 

Compare your predicted  value for the population with the actual population of Mexico for some year after 1982. 

What is your prediction for the population of Mexico in the year 2000? Plot your estimate for the population growth of Mexico from 1980 to 2000.

2. Assume that the Consumer Price Index was set to 100 in 1984 and we want to study the effect of inflation over a 20 year period from 1984 to 2004.  To simplify our calculations, we will assume that the rate of inflation is constant over the 20 year period.  We want to consider a range of rates of inflation from 2% to 10% in increments of 1%. 

Make a table of the  rates of inflation (2%,3%,...,10%), the CPI in 1994, and CPI in 2004. 

Plot the 9 functions which give the CPI for each rate of inflation for the 20 year period. 

(Hint:  define a function for the CPI in terms of both t and k, i.e.,  c[t_,k_].)

3.  Athletic events are held in various locations around the world which are often at many different altitudes.  An athlete is concerned about the effect of high altitudes on his/her performance.  To investigate the effect of different altitudes, we assume that air pressure decays exponentially at 0.4% every 100 feet.  That is, the pressure is modeled by the equation p(x)=p0ekx where k<0, and if we have an initial pressure of p0 at a given altitude, then at 100 feet higher, the pressure is now 0.996 p0.  

Find an expression for p(x). 

Make a table of  the altitude (from 0 to 8000 feet in increments of 500 feet) and the percentage that the air pressure is reduced by in moving from sea level to the given altitude. 

The Olympic Games were held near Mexico City in 1968 and there were records set in the long jump.  If the altitude there was 7340 feet, by what percentage was the air pressure reduced by holding the Games in Mexico City instead of at a location at sea level?

4. Newton's law of cooling states that the rate at which an object cools is proportional to the difference in temperature between the object and the surrounding medium.   For example, if T(t) represents the temperature at time t which at time t=0 has a temperature of T0 degrees, and S represents the temperature of the surrounding environment, then T satisfies the equation
        dT/dt = k (T-S)   where T(0)=T0 .
Find the general solution to this differential equation and verify that your solution satisfies this differential equation.

If a pie is taken from an oven at 350 degrees F and left to cool in a room at 72 degrees F then it will satisfy the differential equation
        dT/dt = k (T-72)   where T(0)=350 .
        
If the pie cools to 250 degrees F in 1/2 an hour, what will it temperature be after 1 hour?  

If someone wants to eat the pie when it is 125 degrees F, how long will they have to wait?  

How long will it take for the pie to cool to 75 degrees F? 

How long will it take for the pie to cool to exactly room temperature? (Be careful!)  

Plot T(t) from t=0 to t=10 .