Numerical Solution of Differential Equations Dr. Alvaro Islas Applications of Calculus I Spring 2008
We live in a world in constant change
We live in a world in constant change
We live in a world in constant change
We live in a world in constant change
We live in a world in constant change
Blue Question: Rate of Change is measured by A Pythagoras theorem. B The zeros of a function. C Derivatives. D Similar triangles. D None of the above.
And change is measured by [C] Derivatives!
Blue Question: Derivatives give the A zeros of a function. B steepness of a function. C asymptotes. D All of the above. E None of the above.
Derivatives give the [B] steepness of a function!
Blue Question: If we KNOW the function that fits the data then 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.
If we KNOW the function then we know [D] All of the above! 0.4 sin(x)/(x-pi) 0 0.2 0-0.2-0.4-0.6-0.8-1 -15-10 -5 0 5 10 15
If we DON T KNOW the function Then we could make a guess. try to fit it to known equations. try to find an equation containing derivatives. Equations containing derivatives are called Differential equations.
Blue Question: Which equations are differential equations? 1) x 2 + y 2 = r 2 2) x 2 + 4xy + y 2 = 1 3) x 2 y + xy + y = 0 ( 4) x 2 + y 2) 4 = 25(x 2 y 2 ) 5) y + y = 0 A) 1 & 3 B) 2 & 4 C) 3 & 5 D) none E) all
Which equations are differential equations? 1) x 2 + y 2 = r 2 2) x 2 + 4xy + y 2 = 1 3) x 2 y + xy + y = 0 ( 4) x 2 + y 2) 4 = 25(x 2 y 2 ) 5) y + y = 0 [C] 3 & 5!
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.
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!
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 its derivative with respect to time. Assume that the only forces acting on the body are gravity and 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
Examples: Spring Motion Consider a spring immersed in a fluid. By Newton s second law and many lab experiments we have found that my = CY KY where m is the mass, K is the spring constant, and C is the damping constant.
Examples: Population Models One species (i) Unlimeted resources and growth rate k. dp dt = kp, P(t) is the population at time t. One species (ii) Limeted resources and competion. ( dp = kp 1 P ), C is the carrying capacity. dt C
Examples: Population Models Two species dx dt dy dt = ax αxy, X(t) is the prey = bx + βxy, Y (t) is the predator
Initial-value Problems Every problem starts somewhere. Derivatives give only rates of change. A problem s complete description is given by a differential equation plus some initial condition(s). dp dt = kp, P(t 0 ) = P 0 d 2 y dt 2 = k 2 y, y(t 0 ) = y 0, y dt (t 0) = v 0
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 is given by y = x 2 + C, since the derivative of a constant is zero. Another simple example is the DE given by y = 32.
Approximate solutions Most differential equations don t have an analytical solution! 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 s first take a geometric view of differential equations. We want to use the fact that the derivative gives the slope of the tangent lines to the curve. Since we know the derivative (from the differential equation), we could draw a bunch of (small tangent lines) and get an idea of the curve.
Direction fields. Example: v = 9.8 0.196v. To obtain a geometric view we use the fact that the derivative gives 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 this case, v = 0 means they are of the form (t, v) = (t, 50)). Plot horizontal arrows at these points to indicate the arrows are horizontal there.
Direction fields. Example: v = 9.8 0.196v. Direction field where the slopes are zero.
Direction fields. Example: v = 9.8 0.196v. Add arrows where the slopes are positive.
Direction fields. Example: v = 9.8 0.196v. Add arrows where the slopes are negative.
Direction fields. Example: v = 9.8 0.196v. Now we can visualize the solution that starts at 30.
Direction fields. Example: v = 9.8 0.196v. Or we can visualize several other solutions.
Red Question Draw the direction field and a few curves for the population equation 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.
The direction field and a few curves are given by P P P x A B 2 1.8 1.6 1.4 1.2 1 0.8 0.6 0.4 0.2 0 2 1.8 1.6 1.4 1.2 1 0.8 0.6 0.4 0.2 0 0 1 2 3 4 5 6 7 8 9 10 t 0 1 2 3 4 5 6 7 8 9 10 t C D 2 1.8 1.6 1.4 1.2 1 0.8 0.6 0.4 0.2 0 2 1.8 1.6 1.4 1.2 1 0.8 0.6 0.4 0.2 0 0 1 2 3 4 5 6 7 8 9 10 t 0 1 2 3 4 5 6 7 8 9 10 t
The direction field and a few curves are given by [C]! 2 1.8 1.6 1.4 1.2 P 1 0.8 0.6 0.4 0.2 0 0 1 2 3 4 5 6 7 8 9 10 t
How do we get the approximate values of f (x)? Using the linear approximation!
Given f (x) the linear approximation is given by [B] f (x) L(x) = f (a) + f (a)(x a)!
Tangent Below the Curve f 10 5 0 5 0 0.5 1 1.5 2 2.5 3 3.5 4 x Figure: The tangent line is completely below the curve and the linear approximation gives an underestimate.
Tangent Above the Curve f 10 5 0 5 4 3.5 3 2.5 2 1.5 1 0.5 0 x Figure: The tangent line is completely above the curve and the linear approximation gives an overestimate.
Tangent Above and Below the Curve f 120 100 80 60 40 20 0 20 10 8 6 4 2 0 2 4 6 8 10 x Figure: The tangent line is above the curve (overestimate) on one side of the tangent point and below (underestimate) on the other side.
Population Models Now we are ready to start working on a real application. Suppose we want to describe a given species population growth. The simplest model assumes that the population rate of change is proportional to the population size. That is dp dt = kp, P 0 = P(0) where k is the constant rate of growth and P 0 is the initial population.
Direction field and the solution for P = 0.02P, P 0 = 1 P = 0.02 P 10 9 8 7 6 P 5 4 3 2 1 0 0 10 20 30 40 50 60 70 80 90 100 t
How do we use L(t) to approximate the solution The linear approximation starts at t = 0 and is given by L 0 (t) = P(0) + P (0) (t 0) = P(0) + k P(0) (t 0) = 1 + 0.02 1 t = 1 + 0.02t 10 8 6 P 4 2 0 2 10 0 10 20 30 40 50 60 70 80 90 100 t
How do we use L(t) to approximate the solution Continued This linear approximation is good only near t = 0, say for 0 t 10. To continue we need to use a new linear approximation at t = 10. It uses the initial value given by the previous approximation. L 1 (t) = L 0 (10) + P (10) (t 10) L 1 (t) = 1.2 + 0.02 1.2 (t 10) L 1 (t) = 1.2 + 0.24 (t 10)
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. 1.5 1.45 1.4 1.35 1.3 1.25 1.2 1.15 1.1 1.05 exact L 0 (t) L 1 (t) 1 0 2 4 6 8 10 12 14 16 18 20
Euler s Method By repeating this step, with timesteps of length h = 10, we can advance the solution to t 3, t 4,..., t N t 1 = t 0 + h = 10 P 1 = P 0 + h (0.02 P 0 ) = 1.2 t 2 = t 1 + h = 20 P 2 = P 1 + h (0.02 P 1 ) = 1.44. t N+1 = t N + h P N+1 = P N + h (0.02 P N ) This procedure is known as Euler s Method.
Euler s Method with two different timesteps. 8 7 6 Population 5 4 3 2 1 0 10 20 30 40 50 60 70 80 90 100 Time Figure: Numerical (h = 10 (dotted line), h = 5 (dashed line)) and exact (solid line) solutions.
Population Model for two species Consider the population of rabits (R) and wolves (W) as described by the Lotka-Volterra equations dr dt dw dt = 0.08R 0.001RW = 0.02W + 0.00002RW
Equilibrium occurs when [C] Both derivatives are equal to zero! That is neither population grows.
There exists an equilibrium point when [B] R = 1000 and W = 80!
Euler s Method for a system of equations The linear approximations at t = t 0 for both the rabit and wolf populations are given just as before L r (t) = R(t 0 ) + dr dt (t 0)(t t 0 ) L w (t) = W (t 0 ) + dw dt (t 0 )(t t 0 ) The difference is that both derivatives are functions of both R and W.
Euler s Method in vector form The linear approximations, as before, are good near t = t 0, say up to t 1 = t 0 + h. Then we need a new approximation at t = t 1 which again is only good near t 2. And so on... ( R1 W 1 ( R2 W 2 ) ) = = ( R0 W 0 ( R1 W 1 ) ( R + (t 0 ) W (t 0 ) ) + ( R (t 1 ) W (t 1 ) ) h ) h ( RN+1 W N+1 ). = ( RN W N ) ( R + (t N ) W (t N ) ) h
Euler s Method in vector form Or replacing the derivatives with their corresponding expressions ( ) ( ) ( R1 R0 0.08R = + 0 0.001R 0 W 0 W 1 W 0 0.02W 0 + 0.00002R 0 W 0 ( ) ( ) ( R2 R1 0.08R = + 1 0.001R 1 W 1 W 1 0.02W 1 + 0.00002R 1 W 1 W 2 ) h ) h ( RN+1 W N+1 ). = ( RN W N ) ( + 0.08R N 0.001R N W N 0.02W N + 0.00002R N W N ) h
A plot of W vs R looks like [C]! 250 tsdat.3 200 150 100 50 0 0 1000 2000 3000 4000 5000 6000 7000
Euler s method with h = 1 gives 250 tsdat.1 200 150 100 50 0 0 1000 2000 3000 4000 5000 6000 7000
Euler s method with h = 0.5 gives 250 tsdat.2 200 150 100 50 0 0 1000 2000 3000 4000 5000 6000 7000
A Modified Euler s method with h = 1 ( R1 W 1 ) = ( R0 W 0 ) ( + 0.08R 0 0.001R 0 W 0 0.02W 0 + 0.00002R 1 W 0 ) h 250 tsdat.3 200 150 100 50 0 0 1000 2000 3000 4000 5000 6000 7000
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.
The Last Question: We have learned [E] All of the above! Have a nice Spring Break!