Upload
doanngoc
View
229
Download
2
Embed Size (px)
Citation preview
Numerical Solution of Differential Equations
Dr. Alvaro Islas
Applications of Calculus ISpring 2008
Dr. A. Islas Numerical ODEs
We live in a world in constant change
Dr. A. Islas Numerical ODEs
We live in a world in constant change
Dr. A. Islas Numerical ODEs
We live in a world in constant change
Dr. A. Islas Numerical ODEs
We live in a world in constant change
Dr. A. Islas Numerical ODEs
We live in a world in constant change
Dr. A. Islas Numerical ODEs
Blue Question:
Rate of Change is measured byA Pythagoras theorem.B The zeros of a function.C Derivatives.D Similar triangles.D None of the above.
Dr. A. Islas Numerical ODEs
And change is measured by
[C] Derivatives!
Dr. A. Islas Numerical ODEs
Blue Question:
Derivatives give theA zeros of a function.B steepness of a function.C asymptotes.D All of the above.E None of the above.
Dr. A. Islas Numerical ODEs
Derivatives give the
[B] steepness of a function!
Dr. A. Islas Numerical ODEs
Blue Question:
If we KNOW the function that fits the datathen we can determine
A The derivative.B The zeros of the function.C The maximum and minimum values.D All of the above.E None of the above.
Dr. A. Islas Numerical ODEs
If we KNOW the function then we know
[D] All of the above!
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
-15 -10 -5 0 5 10 15
sin(x)/(x-pi)0
Dr. A. Islas Numerical ODEs
If we DON’T KNOW the function
Then we couldmake a guess.try to fit it to known equations.try to find an equation containing derivatives.
Equations containing derivatives are called
Differential equations.
Dr. A. Islas Numerical ODEs
Blue Question:
Which equations are differential equations?
1) x2 + y2 = r2
2) x2 + 4xy + y2 = 13) x2y ′′ + xy ′ + y = 0
4)(
x2 + y2)4
= 25(x2 − y2)
5) y ′′ + y = 0
A) 1 & 3 B) 2 & 4 C) 3 & 5 D) none E) all
Dr. A. Islas Numerical ODEs
Which equations are differential equations?
1) x2 + y2 = r2
2) x2 + 4xy + y2 = 13) x2y ′′ + xy ′ + y = 0
4)(
x2 + y2)4
= 25(x2 − y2)
5) y ′′ + y = 0
[C] 3 & 5!
Dr. A. Islas Numerical ODEs
Blue Question:
How do we derive a differential equation?A Using basic principles.B Doing experiments.C By trial and error.D All of the above.E None of the above.
Dr. A. Islas Numerical ODEs
How do we derive a differential equation?
A Using basic principles.B Doing experiments.C By trial and error.D All of the above.E None of the above.
[D] All of the above!
Dr. A. Islas Numerical ODEs
Example: Falling Body
Newton’s second law: Net Force = mass× acceleration.
F = m a = m v ′
where v(t) is the velocity of the falling body, and v ′ is itsderivative with respect to time.Assume that the only forces acting on the body are gravityand air resistance.Gravity is constant on the surface of the earth.Air resistance is proportional to the velocity.Putting it all together we have our first differential equation:
mv ′ = 9.8− γv
Dr. A. Islas Numerical ODEs
Examples: Spring Motion
Consider a spring immersed ina fluid.By Newton’s second law andmany lab experiments wehave found that
mY ′′ = −CY ′ − KY
where m is the mass, K is thespring constant, and C is thedamping constant.
Dr. A. Islas Numerical ODEs
Examples: Population Models
One species (i) Unlimeted resources and growth rate k .
dPdt
= kP, P(t) is the population at time t .
One species (ii) Limeted resources and competion.
dPdt
= kP(
1− PC
), C is the carrying capacity.
Dr. A. Islas Numerical ODEs
Examples: Population Models
Two species
dXdt
= aX − αXY , X (t) is the prey
dYdt
= −bX + βXY , Y (t) is the predator
Dr. A. Islas Numerical ODEs
Initial-value Problems
Every problem starts somewhere.Derivatives give only rates of change.A problem’s complete description is given by a differentialequation plus some initial condition(s).
dPdt
= kP, P(t0) = P0
d2ydt2 = −k2y , y(t0) = y0,
ydt
(t0) = v0
Dr. A. Islas Numerical ODEs
How do we solve a differential equation?
Many differential equations have analytical solutions.These can be given by explicit or implicit formulas.For example an analytical solution to the DE y ′ = 2x isgiven by y = x2 + C, since the derivative of a constant iszero.Another simple example is the DE given by
y ′′ = −32.
Dr. A. Islas Numerical ODEs
Approximate solutions
Most differential equations don’t have an analyticalsolution!The solution has to be approximated.The linear approximation gives a first order approximation.
To get a better idea on how the linear approximation works, let’sfirst take a geometric view of differential equations.We want to use the fact that the derivative gives the slope ofthe tangent lines to the curve. Since we know the derivative(from the differential equation), we could draw a bunch of (smalltangent lines) and get an idea of the curve.
Dr. A. Islas Numerical ODEs
Direction fields. Example: v ′ = 9.8− 0.196v .
To obtain a geometric view we use the fact that the derivativegives the slope of the tangent line and take the following steps:
Find the points where the slopes have given values.For example, start with the points with zero slopes. (In thiscase, v ′ = 0 means they are of the form (t , v) = (t ,50)).Plot horizontal arrows at these points to indicate the arrowsare horizontal there.
Dr. A. Islas Numerical ODEs
Direction fields. Example: v ′ = 9.8− 0.196v .
Direction field where the slopes are zero.
Dr. A. Islas Numerical ODEs
Direction fields. Example: v ′ = 9.8− 0.196v .
Add arrows where the slopes are positive.
Dr. A. Islas Numerical ODEs
Direction fields. Example: v ′ = 9.8− 0.196v .
Add arrows where the slopes are negative.
Dr. A. Islas Numerical ODEs
Direction fields. Example: v ′ = 9.8− 0.196v .
Now we can visualize the solution that starts at 30.
Dr. A. Islas Numerical ODEs
Direction fields. Example: v ′ = 9.8− 0.196v .
Or we can visualize several other solutions.
Dr. A. Islas Numerical ODEs
Red Question
Draw the direction field and a few curves for the populationequation
P ′ = P(1− P)
by taking the following steps:Find the points where the slopes are zero.Draw some arrows with zero slope.Then draw a few arrows with positive slope.And a few with negative slope.Last draw a few curves that follow the arrows.
Dr. A. Islas Numerical ODEs
The direction field and a few curves are given by
A
0 1 2 3 4 5 6 7 8 9 10
0
0.2
0.4
0.6
0.8
1
1.2
1.4
1.6
1.8
2
t
P
C
0 1 2 3 4 5 6 7 8 9 10
0
0.2
0.4
0.6
0.8
1
1.2
1.4
1.6
1.8
2
t
PB
0 1 2 3 4 5 6 7 8 9 10
0
0.2
0.4
0.6
0.8
1
1.2
1.4
1.6
1.8
2
t
P
D
0 1 2 3 4 5 6 7 8 9 10
0
0.2
0.4
0.6
0.8
1
1.2
1.4
1.6
1.8
2
t
x
Dr. A. Islas Numerical ODEs
The direction field and a few curves are given by
[C] !
0 1 2 3 4 5 6 7 8 9 10
0
0.2
0.4
0.6
0.8
1
1.2
1.4
1.6
1.8
2
t
P
Dr. A. Islas Numerical ODEs
How do we get the approximate values of f (x)?
Usingthe
linearapproximation!
Dr. A. Islas Numerical ODEs
Given f (x) the linear approximation is given by
[B] f (x) ≈ L(x) = f (a) + f ′(a)(x − a)!
Dr. A. Islas Numerical ODEs
Tangent Below the Curve
0 0.5 1 1.5 2 2.5 3 3.5 4−5
0
5
10
x
f
Figure: The tangent line is completely below the curve and the linearapproximation gives an underestimate.
Dr. A. Islas Numerical ODEs
Tangent Above the Curve
−4 −3.5 −3 −2.5 −2 −1.5 −1 −0.5 0−5
0
5
10
x
f
Figure: The tangent line is completely above the curve and the linearapproximation gives an overestimate.
Dr. A. Islas Numerical ODEs
Tangent Above and Below the Curve
−10 −8 −6 −4 −2 0 2 4 6 8 10−20
0
20
40
60
80
100
120
x
f
Figure: The tangent line is above the curve (overestimate) on oneside of the tangent point and below (underestimate) on the other side.
Dr. A. Islas Numerical ODEs
Population Models
Now we are ready to start working on a real application.Suppose we want to describe a given species populationgrowth.The simplest model assumes that the population rate ofchange is proportional to the population size. That is
dPdt
= kP, P0 = P(0)
where k is the constant rate of growth and P0 is the initialpopulation.
Dr. A. Islas Numerical ODEs
Direction field and the solution for P ′ = 0.02P, P0 = 1
0 10 20 30 40 50 60 70 80 90 100
0
1
2
3
4
5
6
7
8
9
10
t
P
P ’ = 0.02 P
Dr. A. Islas Numerical ODEs
How do we use L(t) to approximate the solution
The linear approximation starts at t = 0 and is given by
L0(t) = P(0) + P ′(0) · (t − 0)
= P(0) + k · P(0) · (t − 0)
= 1 + 0.02 · 1 · t= 1 + 0.02t
−10 0 10 20 30 40 50 60 70 80 90 100−2
0
2
4
6
8
10
t
P
Dr. A. Islas Numerical ODEs
How do we use L(t) to approximate the solutionContinued
This linear approximation is good only near t = 0, say for0 ≤ t ≤ 10.To continue we need to use a new linear approximation att = 10.It uses the initial value given by the previous approximation.
L1(t) = L0(10) + P ′(10) · (t − 10)
L1(t) = 1.2 + 0.02 · 1.2 · (t − 10)
L1(t) = 1.2 + 0.24 · (t − 10)
Dr. A. Islas Numerical ODEs
How do we use L(t) to approximate the solution
Which again is good only for t near t = 10, say for 10 ≤ t ≤ 20.
0 2 4 6 8 10 12 14 16 18 201
1.05
1.1
1.15
1.2
1.25
1.3
1.35
1.4
1.45
1.5
exactL
0(t)
L1(t)
Dr. A. Islas Numerical ODEs
Euler’s Method
By repeating this step, with timesteps of length h = 10, we canadvance the solution to t3, t4, . . . , tN
t1 = t0 + h = 10 P1 = P0 + h · (0.02 · P0) = 1.2t2 = t1 + h = 20 P2 = P1 + h · (0.02 · P1) = 1.44
...tN+1 = tN + h PN+1 = PN + h · (0.02 · PN)
This procedure is known as Euler’s Method.
Dr. A. Islas Numerical ODEs
Euler’s Method with two different timesteps.
0 10 20 30 40 50 60 70 80 90 1001
2
3
4
5
6
7
8
Time
Pop
ulat
ion
Figure: Numerical (h = 10 (dotted line), h = 5 (dashed line)) andexact (solid line) solutions.
Dr. A. Islas Numerical ODEs
Population Model for two species
Consider the population of rabits (R) and wolves (W) asdescribed by the Lotka-Volterra equations
dRdt
= 0.08R − 0.001RW
dWdt
= −0.02W + 0.00002RW
Dr. A. Islas Numerical ODEs
Equilibrium occurs when
[C] Both derivatives are equal to zero!That is neither population grows.
Dr. A. Islas Numerical ODEs
There exists an equilibrium point when
[B] R = 1000 and W = 80!
Dr. A. Islas Numerical ODEs
Euler’s Method for a system of equations
The linear approximations at t = t0 for both the rabit and wolfpopulations are given just as before
Lr (t) = R(t0) +dRdt
(t0)(t − t0)
Lw (t) = W (t0) +dWdt
(t0)(t − t0)
The difference is that both derivatives are functions of both Rand W .
Dr. A. Islas Numerical ODEs
Euler’s Method in vector form
The linear approximations, as before, are good near t = t0, sayup to t1 = t0 + h. Then we need a new approximation at t = t1which again is only good near t2. And so on . . .(
R1W1
)=
(R0W0
)+
(R′(t0)W ′(t0)
)· h(
R2W2
)=
(R1W1
)+
(R′(t1)W ′(t1)
)· h
...(RN+1WN+1
)=
(RNWN
)+
(R′(tN)W ′(tN)
)· h
Dr. A. Islas Numerical ODEs
Euler’s Method in vector form
Or replacing the derivatives with their correspondingexpressions(
R1W1
)=
(R0W0
)+
(0.08R0 − 0.001R0W0
−0.02W0 + 0.00002R0W0
)· h(
R2W2
)=
(R1W1
)+
(0.08R1 − 0.001R1W1
−0.02W1 + 0.00002R1W1
)· h
...(RN+1WN+1
)=
(RNWN
)+
(0.08RN − 0.001RNWN
−0.02WN + 0.00002RNWN
)· h
Dr. A. Islas Numerical ODEs
A plot of W vs R looks like
[C] !
0
50
100
150
200
250
0 1000 2000 3000 4000 5000 6000 7000
’tsdat.3’
Dr. A. Islas Numerical ODEs
Euler’s method with h = 1 gives
0
50
100
150
200
250
0 1000 2000 3000 4000 5000 6000 7000
’tsdat.1’
Dr. A. Islas Numerical ODEs
Euler’s method with h = 0.5 gives
0
50
100
150
200
250
0 1000 2000 3000 4000 5000 6000 7000
’tsdat.2’
Dr. A. Islas Numerical ODEs
A Modified Euler’s method with h = 1
(R1W1
)=
(R0W0
)+
(0.08R0 − 0.001R0W0
−0.02W0 + 0.00002R1W0
)· h
0
50
100
150
200
250
0 1000 2000 3000 4000 5000 6000 7000
’tsdat.3’
Dr. A. Islas Numerical ODEs
The Last Question: We have learned
A About differential equations.B How to derive simple differential equations.C How to use the linear approximation to solve them.D How we apply these ideas to systems of
equations.E All of the above.
Dr. A. Islas Numerical ODEs
The Last Question: We have learned
[E] All of the above!
Have a nice Spring Break!
Dr. A. Islas Numerical ODEs