MATH 1170: Calculus for Biologists I (Fall 2010)

advertisement
MATH 1170: Calculus for Biologists I (Fall 2010)
Lab Meets: November 30, 2010
Report due date: December 7, 2010
Section 002: Tuesday 9:40−10:30am
Section 003: Tuesday 10:45−11:35am
Lab location − LCB 115
Lab instructor − Erica Graham, graham@math.utah.edu
Lab webpage − www.math.utah.edu/~graham/Math1170.html
Lab 12
General Lab Instructions
Instructions:
During the lab any necessary commands will be introduced and illustrated through examples.
Plain text appears in black inside of a plain square bracket to the left of the worksheet.
Maple commands appear in red and lines with commands begin with a red Maple prompt.
Maple output (expressions, values, and warnings) appears in blue following the commands, within the same
execution group (bracket).
Maple errors appear in pink following the commands, within the same execution group.
If you don’t want to make a text box, you can type comments to yourself or to me if you begin the line with
#.
To make a text box, click the ’T’ button on the toolbar.
Homework problems will be listed at the bottom of each lab. Please copy these problems to a new
worksheet with your full name and section number in the first line, execute required Maple commands, and
answer any questions. Your answers should be given in a short lab report (usually 2−3 pages). The lab
report should consist of the problem (as I have stated it), Maple code used to generate data or graphs, and
your answers to questions or interpretations of data and/or graphs. You can type your answers or write
them by hand on your printed out sheets. Please do not include errors in your reports.
Each report will be due to me by the start of the next lab session.
In−class Exploration
Review: Last week, we used Newton’s method to solve equations numerically. The basis of Newton’s
Method is solving for roots of various tangent line approximations.
Background: The topic of this lab is Euler’s Method, which uses tangent lines to numerically approximate
the solutions of differential equations.
restart;
The solution of a differential equation gives us a particular quantity when we only know its derivative.
Suppose we wish to find the solution to the differential equation
db/dt = f(t), b(0) = 1.0,
where f(t) is the following function:
f:=t−>exp(−t);
f := t e t
(2.1)
We can plot f(t) and think about what the solution might do.
plot(f(t),t=0..5);
1.0
0.7
0.5
0.3
0.1
0
1
2
3
4
5
t
It looks as though the solution should always increase, yet increase more slowly with larger t values. To
use Euler’s Method, we need to specify a time step, dt, and define the initial condition b0=1.0. For the
purpose of generalization, we’ll define our initial time, t0=0, as well.
dt:=1.0;
b0:=1.0;
t0:=0;
dt := 1.0
b0 := 1.0
t0 := 0
(2.2)
We denote the tangent line approximations by fhat. Since we’re already dealing with the derivative, f(t), we
don’t have to compute any derivatives explicitly. fhat0(t), for example, is the tangent line approximation of
b(t) at base point t0. Note that fhat0(t0) is exactly equal to our initial condition.
bhat0:=t−>b0+f(t0+0*dt)*(t−(t0+0*dt)); bhat0(t);## line 0
init:=bhat0(t0); ## initial condition
bhat0 := t b0 f t0 0 dt t t0 0 dt
1.0 1. t
init := 1.0
(2.3)
Using our previous tangent line evaluated at t = t0+1*dt, we can compute our second tangent
approximation, fhat2(t), with base point t = t0+1*dt.
b1:=bhat0(t0+1*dt);
bhat1:=t−>b1+f(t0+1*dt)*(t−(t0+1*dt));
b1 := 2.0
bhat1 := t b1 f t0 dt t t0 dt
(2.4)
Then we can do the same thing again, creating a new approximation, and plot all of our results.
b2:=bhat1(t0+2*dt);
bhat2:=t−>b2+f(t0+2*dt)*(t−(t0+2*dt));
plot([f(t),bhat0(t),bhat1(t),bhat2(t)],t=0..5,color=["Black",
"Blue","DarkTurquoise","ForestGreen"],linestyle=[1,3,3,3],
thickness=[2,1,1,1],legend=["dbdt","bhat0","bhat1","bhat2"]);
b2 := 2.367879441
bhat2 := t b2 f t0 2 dt t t0 2 dt
6
5
4
3
2
1
0
1
2
3
4
5
t
dbdt
bhat2
bhat0
bhat1
The process of approximation can be automated using a do loop, which we explored in earlier labs. We will
first initialize the code using our initial condition, b[0] = b0 = 1. We also need to decide how many line
segments N we want to draw. ’dt’ will be the same as above (so we will not redefine it).
b[0]:=b0:
N:=5;
N := 5
(2.5)
To create a useful approximation, the following loop will compute the estimates of b(t) and save them to a
list of ’lines’ connecting each adjacent pair of estimates (for useful plotting).
for j from 0 to (N−1) do
b[j+1]:=evalf(b[j]+f(t0+j*dt)*dt):
lines[j+1]:=[[j*dt,b[j]],[(j+1)*dt,b[j+1]]]:
end do:
With our approximate solution in hand, we can now plot the results, along with our original plot above.
p1:=plot([f(t),bhat0(t),bhat1(t),bhat2(t)],t=0..5,color=["Black",
"Blue","DarkTurquoise","ForestGreen"],linestyle=[1,3,3,3],
thickness=[2,1,1,1],legend=["dbdt","fhat0","fhat1","fhat2"]):
p2:=plot([seq(lines[j],j=1..N)],t=0..5,color="Magenta",thickness=
2):
plots[display](p1,p2);
6
5
4
3
2
1
0
1
2
3
4
t
dbdt
fhat2
fhat0
fhat1
5
Assuming we know the exact solution to be ’ans(t),’ we can compare it to our Euler’s Method estimate.
ans:=t−>2−exp(−t):
p3:=plot(ans(t),t=0..5,0..3,color="Black",thickness=3):
plots[display](p3,p2);
3
2
1
0
0
1
2
3
4
5
t
Lab 12 Homework Problems
Please copy this entire section into a new worksheet, and save it as something
you’ll remember.
Your Full Name:
Your (registered) Lab Section:
Useful Tip #1: Read each problem carefully, and be sure to follow the directions specified for each
question!
Useful Tip #2: Don’t be afraid to troubleshoot! Does your answer make sense to you? If not, explore why.
If you’re still unsure, ask me.
Paper−saving tip: Make the size of your output graphs smaller to save paper when you print them. Please
ask me if you’re unsure of how to do this. (You can see how much paper you’d use beforehand by going to
File
Print Preview.)
This assignment will walk you through solving the differential equation dh/dt = g(t) with initial condition
h(0)=10, using Euler’s Method.
(1)(a) Enter the function g(t) = 5*t*exp(−t^2).
## g(t)
(b) Enter the initial condition as h[0] = 10, and plot g(t) for t=0..3. Note: be sure to use the Maple
subscript notation, as indicated.
## h[0]
## plot
(c) What should the solution h(t) of the differential equation look like on the interval t=0..3 given the graph
of g(t)? (Describe increasing/decreasing behavior and concavity.)
Use Euler’s Method to solve the differential equation dh/dt=g(t), h(0)=10 for dt=1 by carrying out the
following steps.
(2)(a) Step 1: Enter the step size, dt, and the initial time, t0=0.
## dt
## t0
(b) Step 2: Choose the number of lines you want to draw, N, to fill the entire interval t=0..3. Your N
should be an integer. The idea: smaller dt values would require more lines to fill up the same amount of
space.
## N, chosen carefully
(c) Step 3: Copy and paste the do loop from the in class exercises. Edit the code appropriately to match the
current problem (i.e. pay attention to the functions you are dealing with), and run Euler’s Method for the
differential equation above, starting from t0. Change the name of the ’lines’ list to ’lines1.’
## Euler’s Method
(3)(a) Define the actual answer as the function ans(t) = −(5/2)*exp(−t^2)
## ans(t)
(b) Save a plot of ans(t) to p1 for t=0..3 and for y−axis values from 10 to 12.5.
Required:
[1] Specify "Black" as the color for the curve.
[2] Specify a line style for the curve.
[3] Specify a thickness of 3 for the curve.
## plot p1
(c) Save a plot of ’lines1’ for t=0..3 to p2 using the seq( ) command. Hint: copy and paste the code we used
in class and modify it accordingly.
Required:
[1] Specify a single color for all the lines that is different from the one you used for ans(t).
[2] Specify a single line style for all the lines that is different from the one you used for ans(t).
## plot p2
(d) Use plots[display]( ) to put p1 and p2 on the same set of axes.
## plot both
Is Euler’s Method with dt=1 a good approximation for the solution to the differential equation? Why or
why not?
The remaining exercises will explore the role of changes in dt within Euler’s Method.
(4)(a) Now set dt equal to 0.5, and redefine N to fill the interval from 0 to 3.
## dt
## N
(b) Re−run Euler’s Method for these new values. Change the name of the ’lines1’ list to ’lines2.’
## Euler’s Method
(c) Save a plot of ’lines2’ for t=0..3 to p3 using the seq( ) command. Hint: copy and paste the code we used
in class and modify it accordingly.
Required:
[1] Specify a single color for all the lines that is different from all previous colors used.
[2] Specify a single line style for all the lines that is different from all previous line styles used.
## plot p3
(5) Repeat the process in the previous problem for dt=0.1:
[i] Redefine dt and N;
[ii] Run Euler’s Method, saving the result to ’lines3.’
[iii] Save a plot of ’lines3’ to p4, following the same color and line style instructions as above.
## all steps within these four lines
## feel free to use this space
## feel free to use this space
## feel free to use this space
(6) Repeat the process for dt=0.01:
[i] Redefine dt and N;
[ii] Run Euler’s Method, saving the result to ’lines4.’
[iii] Save a plot of ’lines4’ to p5, following the same color and line style instructions as above.
## all steps within these four lines
## feel free to use this space
## feel free to use this space
## feel free to use this space
(7)(a) Use plots[display]( ) to put p1 through p5 on the same set of axes.
## display all plots
(b) Given the results depicted in the previous plot, how does step size affect Euler’s Method?
Download