You are on page 1of 12

MATHEMATICS

MTHC02C02
Lecture 7

First Order Differential Equations


A first order differential equation could be written on the form

dy = f ( x, y ) dx

dy = 2 xy , y (1) = 25 dx And assume that we are interested to find the value of y at x = 2


As an example, consider the following equation By solving this equation we have

1 y dy = 2 x dx Ln y = x 2 + c y=e
x2 +c

=e

x2 c

y = Ae x

Now, at

x = 1 , y = 25

Then 25 = Ae 1

A = 67.957
y = 67.957e
x2

If we are interested to find the value of y at x = 2 we will have

y = 67.957e 4 = 1.2446759
Now we will study some numerical methods of solving first order differential equations

Euler Method
Consider the first order differential equation on the form

dy = f ( x, y ) dx
We know that

, y ( x0 ) = y0

dy y ( x + h) y ( x ) = lim = f ( x, y ) h 0 dx h
Then one take the approximation

y ( x + h) y ( x ) f ( x, y ) h

or

y ( x + h ) y ( x ) + h f ( x, y )
yn+1 = yn + h f ( xn , yn )

Then we can use the following form

Example 1 Use Euler method to solve the differential equation = x + y to find y at x = 2 by using step length h = 0.25 dx Solution We have h = 0.25

dy

, y (1) = 4

f ( x, y ) = x + y

yn+1 = yn + h f ( xn , yn )
Then at

xn
1

yn
4

f ( xn , yn )
3 3.5 4.125 4.90625

h f ( xn , yn )
0.75 0.875 1.03125 1.2265625

x=2

y = 7.8828125

1.25
1.5

4.75 5.625 6.65625 7.8828125

1.75 2

______

______

Example 2 Solve the following initial value problem over the interval t = 0 to t = 0.5 using a step size h = 0.1

dy = (1 + 2t ) y dt tn
0 0.1
0.2

, y (0) = 1 yn
1 1.1

Solution We have

f (tn , yn )
1 1.258571 1.550058 1.880162 2.254588

h f (tn , yn )
0.1 0.125857 0.155006 0.188016 0.2254589

h = 0.1 f (t , y ) = (1 + 2t ) y

yn+1 = yn + h f (tn , yn )
Then at

1.225857 1.380863 1.568879 1.794338

0.3 0.4 0.5

t = 0.5

y = 1.794338

______

______

Runge-Kutta Method of Order Two, Heuns Method


Consider the first order differential equation on the form

dy = f ( x, y ) dx
We have that

, y ( x0 ) = y0

k1 = f ( xn , yn ) k2 = f ( xn + h, yn + h k1 )

yn+1 = yn +

h ( k1 + k2 ) 2

Then by using a suitable step size h we can then get the solution y at some give value of x

Example 3 Solve the following differential equation by using the second order Runge-Kutta (Heuns) method over the interval from t = 0 to t = 1 using a step size of h = 0.25 where .

dy = (1 + 2t ) y dt
Solution We have

, y (0) = 1

h = 0.25 , f (t , y ) = (1 + 2t ) y k1 = f (tn , yn ) k2 = f (tn + h, yn + h k1 )


yn+1 = yn + h ( k1 + k2 ) 2
The calculations will be as in the following table

h = 0.25 , f (t , y ) = (1 + 2t ) y
k1 = f (tn , yn ) k2 = f (tn + h, yn + h k1 ) h yn+1 = yn + ( k1 + k2 ) 2

tn
0 0.25
0.5

yn
1 1.3346 1.8836 2.7277

k1 = f (tn , yn )
1 1.7329 2.7449 4.1289

tn + h
0.25 0.5 0.75

yn + hk1
1.25 1.7679 2.5699

k2 = f (tn + h, yn + h k1 )
1.677 2.6592 4.0077

0.75 1

1
______

3.7599
______

5.8171
____________

3.9709

______

Runge-Kutta Method of Order Three


Consider the first order differential equation on the form

dy = f ( x, y ) dx
We have that

, y ( x0 ) = y0

k1 = f ( xn , yn ) 1 1 k2 = f ( xn + h, yn + h k1 ) 2 2 k3 = f ( xn + h, yn h k1 + 2hk2 )

h yn+1 = yn + ( k1 + 4k2 + k3 ) 6
Then by using a suitable step size h we can then get the solution y at some give value of x

Runge-Kutta Method of Order Four


Consider the first order differential equation on the form

dy = f ( x, y ) dx
We have that

, y ( x0 ) = y0

k1 = f ( xn , yn ) 1 1 k2 = f ( xn + h, yn + h k1 ) 2 2 1 1 k3 = f ( xn + h, yn + h k2 ) 2 2 k4 = f ( xn + h, yn + h k3 )

yn+1 = yn +

h ( k1 + 2k2 + 2k3 + k4 ) 6

Then by using a suitable step size h we can then get the solution y at some give value of x

Formoredetailsaboutthislectureyoumayusethefollowing:

Ourtextbook,chaptertwentyfivesections25.1,25.2and25.3 NumericalAnalysisby:BurdenandFares,Brooks/ColePublications NumericalRecipesinC;TheArtofScientificComputingby:WilliamH. Press,BrianP.Flannery,SaulA.Teukolsky andWilliamT.Vetterling, CambridgeUniversityPressPublications


http://tutorial.math.lamar.edu/Classes/DE/EulersMethod.aspx http://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods http://www.analyzemath.com/calculus/RungeKutta/RungeKutta.html http://www.efunda.com/math/num_ode/num_ode.cfm http://www.codeproject.com/Articles/43607/Solving-ordinary-differentialequations-in-C http://www.physicsforums.com/showthread.php?t=1448

You might also like