chap2_ode

26
MATH1251 – Calculus Chapter 2: Oridinary Differential Equations A/Prof Thanh Tran School of Mathematics and Statistics The University of New South Wales Sydney, Australia Red Centre Room 4061 Email: [email protected] 1 Outline 1 ODEs and IVPs 2 First order ODEs Separable ODEs First order linear ODEs Exact ODEs Substitutions for ODEs Modelling with first order ODEs 3 Second order ODEs The homogeneous case The non-homogeneous case Modelling with second order ODEs 4 Linear ODEs: a theoretical view 5 Numerical methods 2 What is an ordinary differential equation (ODE)? A differential equation is an equation that relates an unknown function with one or more of its derivatives. When only ordinary derivatives, rather than partial derivatives, are involved, the equations are called ordinary differential equations (ODEs). Differential equations involving partial derivatives are called partial differential equations (PDEs). They are not studied in this course. ODEs and IVPs 3 General form Definition 1 An ordinary differential equation or ODE is an equation involving one independent real variable (e.g. x R), one dependent real variable (e.g. u : R R) and finitely many of its derivatives. Thus it is of the form F(x, u(x), u (x),..., u (n) (x)) = 0. (1) Example 2 The following are examples of ODEs u (x)= 2u(x)+ 3x u ′′ (x)= u (x)+ u 2 (x)+ x 3 ODEs and IVPs 4

Upload: kenny013

Post on 18-Aug-2015

215 views

Category:

Documents


0 download

DESCRIPTION

Math Lecture 1251 UNSW uploaded 1 for 1

TRANSCRIPT

OutlineMATH1251 CalculusChapter 2: Oridinary Differential Equations

1

ODEs and IVPs

2

First order ODEsSeparable ODEsFirst order linear ODEsExact ODEsSubstitutions for ODEsModelling with first order ODEs

3

Second order ODEsThe homogeneous caseThe non-homogeneous caseModelling with second order ODEs

4

Linear ODEs: a theoretical view

5

Numerical methods

A/Prof Thanh TranSchool of Mathematics and StatisticsThe University of New South WalesSydney, AustraliaRed Centre Room 4061Email: [email protected]

1

What is an ordinary differential equation (ODE)?

2

General formDefinition 1An ordinary differential equation or ODE is an equation involving oneindependent real variable (e.g. x R), one dependent real variable(e.g. u : R R) and finitely many of its derivatives. Thus it is of theformF (x, u(x), u (x), . . . , u (n) (x)) = 0.(1)

A differential equation is an equation that relates an unknownfunction with one or more of its derivatives.When only ordinary derivatives, rather than partial derivatives, areinvolved, the equations are called ordinary differential equations(ODEs).

Example 2

Differential equations involving partial derivatives are called partialdifferential equations (PDEs). They are not studied in this course.

The following are examples of ODEsu (x) = 2u(x) + 3xu (x) = u (x) + u 2 (x) + x 3

ODEs and IVPs

3

ODEs and IVPs

4

Notation

Motivation

Rather than

Engineering and Science are built on models of the physicalworld. Mostly, these models are mathematical models which allowprediction of future or distant quantities.

u (x) = u (x) + xu 2 (x) + x 3we can writey (x) = y (x) + xy 2 (x) + x 3

At school you studied the solutions of (at least) two ordinarydifferential equations. These were the growth-decay equation,

y = y + xy 2 + x 3d 2ydy+ xy 2 + x 3=dxdx 2 = u + tu 2 + t 3u

dP= kPdtand the simple harmonic motion equation

Whether we use x or t, y or u or f does not matter. What matters is thestructure of the equation. Thus the general form (1) can also be writtenasF (x, y, y , . . . , y (n) ) = 0.ODEs and IVPs

d 2x= n2 x.dt 2More important equations:5

ODEs and IVPs

6

Order of an ODEDefinition 3 Black and Scholes equation (1973).V12VV+ 2 S 2 2 + rS rV = 0t2SS

The order of an ODE is the order of the highest derivative present.Example 4

Nobel Prize for Economics (1997).

Determine the order of each of the following equations:dydxy + 2xy 2dy+ydxy + xy 2 3d y+ y 5ydx 2

Schrdinger equation (1926).~2 2 (~x , t) + V (x, t)(~x , t)i~ (~x , t) = t2mNobel Prize for Physics (1933).

ODEs and IVPs

7

ODEs and IVPs

= y + x 2,= 0,= 0,= sin y,= ex .8

Linear ODEs Which equations in Example 4 are linear? Linear first order ODEs can always be solved by using an integratingfactor. This will be discussed in the next section.

Definition 5An nth order ODE is said to be linear if it is a linear combination of thefirst n derivatives of the dependent function

If a0 , a1 , . . . are constants (independent of x) then the generalsolution may be found if one can solve a certain nth degreepolynomial equation; see Section 3.

d nyd n2 ydyd n1 y+ an1 (x) n1 + an2 (x) n2 + . . . + a1 (x)+ a0 (x)y = f (x).dx ndxdxdxIf f (x) 0 the ODE is homogeneous.

ODEs and IVPs

Second order linear ODEs with non-constant coefficients a0 and a1are studied in MATH2130.

9

ODEs and IVPs

10

Solution to an ODE

Implicit solution

Definition 6

Sometimes a solution to an ODE is given in implicit form.Example 8

A solution to an ODE is a differentiable function which satisfies thegiven equation.

Show that the function y given by

Example 7Show that y =

y + tan1 y =x42 5x 2 is a solution to y = y + x 3 .2x

is a solution toy =

ODEs and IVPs

11

ODEs and IVPs

x22

x(1 + y 2 ).2 + y2

12

Initial value problems (IVPs)

Example 10Solve y = ex given y(0) = 3 and y (0) = 2.

Definition 9An initial value problem is an ODE of order n together with a set ofvalues of the solution and its derivatives up to its first (n 1)derivatives at some fixed point. These values are called the initialconditions of the IVP. More precisely, an IVP reads as: Find a functiony satisfyingF (x, y, y , . . . , y (n) ) = 0,y(x0 ) = C0 ,

y (x0 ) = C1 ,

...,

y (n1) (x0 ) = Cn1 .

ODEs and IVPs

13

ODEs and IVPs

14

Existence and uniqueness of solutions of an IVPExample 12Example 11

Consider the IVP

Consider the following first order IVPs:1

2

y = xy

y = x and y(0) = 1, which has precisely one solution, namely,y = x 2 /2 + 1;

y(1) = 2

y = 3y 2/3 and y(0) = 0, which has two solutions, namely, y = 0and y = x 3 ;

3

xy = y 1 and y(0) = 1, which has infinitely many solutions,namely, y = 1 + cx where c is an arbitrary constant;

4

|y | + |y| = 0 and y(0) = 1, which has no solutions.

ODEs and IVPs

Let f (x, y) = xy. Then the slope of the solution curve at the point (1, 2)is f (1, 2) = 2. The slope of the solution curve at a point (x, y) is f (x, y).This helps to get an idea how the solution curve looks like near thepoint (1, 2). Graph: . . .

15

ODEs and IVPs

16

Existence and uniqueness of solutions of an IVP(cont.)

Solving ODEs and IVPsRemarksThere is no universal method for solving ODEs. For some ODEs itmay not even be possible to find an implicit solution. In this caseone has to resort to numerical methods to find an approximatesolution. Two simple numerical methods will be presented in thelast section. More efficient methods are topics of higher yearcourses (e.g., MATH2301).

Theorem 13Assume that f : R2 R is continuous. If on some rectangle Scontaining (x0 , y0 ) there is an M > 0 such that|f (x, y1 ) f (x, y2 )| M|y1 y2 | for all (x, y1 ) S, (x, y2 ) S,then the IVP

In the sequel we will learn solution techniques for three particularfirst order ODEs, namely, separable equations, linear equations,and exact equations.

y = f (x, y)y(x0 ) = y0

We will also learn how to solve second order ODEs with constantcoefficients.

has a unique solution on some open disk centred at (x0 , y0 ).

ODEs and IVPs

17

Separable ODEs

ODEs and IVPs

18

Solving a separable equationLetting h(y) = 1/H(y), we can rewrite (2) as

Definition 14A separable equation has the formdy= g(x)H(y),dx

h(y)(2)

i.e., we can separate x and y.Example 15Which of the following equations is separable?qdy= x 1 y2dxdy= ex+ydxdy= ln(xy).dxFirst order ODEs

Separable ODEs

dy= g(x).dx

Integrate both sides with respect to x:ZZdyh(y)dx = g(x) dxdxorZZh(y) dy = g(x) dx.Carry out the integrations and try to find an explicit expression of yas a function of x if possible.If we have the IVP defined with y(x0 ) = y0 then we obtainZ yZ xh(s) ds =g(t) dt.y0

19

First order ODEs

x0

Separable ODEs

20

Example 17

Example 16Solve y = x

p

Solve

1 y 2.

First order ODEs

y =

Separable ODEs

21

First order ODEs

Definition 18 (First order linear ODEs)

Example 19

A first order linear ODE is an ODE of the form

Solve

dy+ f (x)y = g(x),dx

ey,x2 + 1

y(0) = 1.

Separable ODEs

22

First order linear ODEs

24

dy+ 3y = ex .dx

where f and g are given functions.Solution techniqueCalculate the integrating factor: h(x) = econstant of integration).

R

f (x) dx

(ignoring the

Multiply the given equation by h(x) and use the product rule fordifferentiation for the left-hand side to rewrite the resultingequation as

dh(x)y = g(x)h(x).dxIntegrate both sides. Dont forget the constant of integration!First order ODEs

First order linear ODEs

23

First order ODEs

Example 20Solve

Example 21

ydy+ = x subject to y = 4 when x = 3.dxx

First order ODEs

First order linear ODEs

Solve x

25

Exact equations

dy+ (x + 1)y = 2.dx

First order ODEs

IfM=

Many first order ODEs can be written in the formdyM(x, y) + N(x, y)= 0.dxdIf the left-hand side can be written asF (x, y(x)) then thedxequation has a solution in implicit form F (x, y) = C.

(3)

and N =

F,y

(4)

then reversing the above steps, we could conclude that thesolution to (3) was F (x, y) = C.

Recall that if F and all its partial derivatives up to order 2 are2F2F=. This together with (4) impliesxyyx

continuous, then

F (x, y) = C,which defines y implicitly in terms of x. By differentiating withrespect to x we obtain

NM=.yx

FF dy+= 0.xy dxExact ODEs

Fx

26

Does such a function F (x, y) exist? How to construct F (x, y) if itexists?

When does such a case happen? Given a function F (x, y) andany constant C, consider the expression

First order ODEs

First order linear ODEs

It turns out that the above condition is also sufficient for F to exist.27

First order ODEs

Exact ODEs

28

Example 23Solve (2x + y + 1)dx + (2y + x + 1)dy = 0.

Definition 22An ODE of the formM(x, y) + N(x, y)is called exact if

dy=0dx

(5)

NM=.yx

NoteEquation (5) is also written in the formM(x, y)dx + N(x, y)dy = 0.

First order ODEs

Exact ODEs

29

First order ODEs

Exact ODEs

30

(6)(7)(8)Example 24(9)

Solve

2xy + 3x 2 y 2dy.= 2dxx + 2x 3 y + 1

NoteWe can first integrate (7) with respect to y (treating x as a constant),then compute F /x and compare with (6). Note that the constant (cf.(8)) is C1 (x).

First order ODEs

Exact ODEs

31

First order ODEs

Exact ODEs

32

(10)

Example 25Solve(x 2 y + y 3 )

dy+ xy 2 + sinh(2x) = 0.dx

(12)

First order ODEs

Exact ODEs

33

First order ODEs

Exact ODEs

34

(13)(14)

Substitutions

(15)

If the ODE is not linear, separable or exact then it may be possible touse a change of variables so that the ODE in the new variables islinear, separable or exact.y dyEquation of the form=gdxxSetting y(x) = xv(x) will lead to a separable ODE.Proof: Differentiating y = vx with respect to x and substituting into thegiven equation yielddvx + v = g(v),dxordvg(v) v=.dxxThis is a separable equation.

First order ODEs

Exact ODEs

35

First order ODEs

Substitutions for ODEs

36

Example 26Solve

When does an equation have the formdy+ x 2 + y 2 = 0.2xydx

y dy=g?dxx

Homogeneous function of degree 0To check if the ODE

dy= F (x, y)dxy dyor not, check whether F is homogeneous of=gis of the formdxxdegree 0, that is,F (x, y) = F (x, y)

First order ODEs

Substitutions for ODEs

37

Example 27Solve

First order ODEs

R.

Substitutions for ODEs

38

Example 28

y y2 + x2dy= sin.dxx y2 x2

Show that the substitution v(x) = y 4 (x) transforms the equation2xy y = 10x 3 y 5into a linear equation. Then solve the ODE.

First order ODEs

Substitutions for ODEs

39

First order ODEs

Substitutions for ODEs

40

Newtons Law of Cooling

Example 29A dead body is discovered by a cleaner in a hotel room at 11am. Aforensic scientist arrives at the scene at 11.30am and records thetemperature of the body at 24.5 C. The body temperature is recordedagain an hour later at 24.0 C. Estimate the time of death given that thehotel room is at constant temperature 20 C and normal bodytemperature is 36.5 C.

The rate of decrease of temperature is proportional to the differencebetween the temperature of an object and its surroundingsdT= k (T (t) TA )dtwhereTA is the ambient temperature in CT (t) is the temperature of object after time tk is some unknown proportionality constantThis is widely used in forensics.

First order ODEs

Modelling with first order ODEs

41

First order ODEs

Modelling with first order ODEs

42

Mixing problemsExample 30Initially 50 grams of salt is dissolved in a tank holding 300 litres ofwater. A brine solution is pumped into the tank at a rate of 3 litres/minand the well-stirred solution is then pumped out at a slower rate of 2litres/min. If the concentration of the solution entering is 2 grams/litre,determine the amount of salt in the tank at any time.

First order ODEs

Modelling with first order ODEs

43

First order ODEs

Modelling with first order ODEs

44

First order ODEs

Modelling with first order ODEs

45

First order ODEs

Modelling with first order ODEs

46

47

First order ODEs

Modelling with first order ODEs

48

Population modelsExample 31A culture initially has x0 bacteria. At t = 1 hour the number of bacteriais measured to be 32 x0 . If the rate at which bacteria grows isproportional to the number of bacteria present, determine the timenecessary for the number of bacteria to triple.

First order ODEs

Modelling with first order ODEs

Different population models

Second order linear ODEs with constant coefficients

MATH1231/1241 NotesdP= kP for k > 0 (Malthus 1798); Exponential growth:dt

Homogeneous Equation (HE)

Bounded growth:

y + ay + by = 0where y = y(x) is an unknown function, a and b are constants.

dP= k(Pc P);dt

Non-homogeneous Equation (NE)y + ay + by = f (x)

Logistic growth:

First order ODEs

dP= kP(Pc P) (Verhulst 1838).dt

Modelling with first order ODEs

where y = y(x) is an unknown function, a and b are constants, andf (x) is a given function.

49

Second order ODEs

50

The homogeneous caseLemma 32If y1 and y2 are two solutions of (HE) then so is Ay1 + By2 where A andB are constants.Lemma 33(HE) has two linearly independent solutions, and every solution is alinear combination of these solutions.Proof: See e.g. MATH2601, MATH2221.

Second order ODEs

The homogeneous case

51

Second order ODEs

The homogeneous case

52

How to find two linearly independent solutions of (HE)?

Example 34Solve y 5y + 6y = 0.

Rewrite (HE): y + ay + by = 0.Look for a solution that does not change too much whendifferentiated so that the terms on the left-hand side cancel eachother out to give zero.Try y = ex where is a constant to be determined.Differentiate and substitute into (HE):

ex 2 + a + b = 0,

which gives, after dividing by ex ,

2 + a + b = 0.

(16)

So, y = ex is a solution to (HE) if and only if is a solutionof (16). This equation is called the characteristic equation of (HE).Second order ODEs

The homogeneous case

53

Three different cases

y1 = e(+i)x = ex eix

y1 + y2eix= ex2ixy1 y2x ez2 ==e2

A, B R;

z1 =

see Lemma 33.Case 2: If the characteristic equation (16) has one double root ,then y1 = e1 x . It turns out that y2 = xe1 x is another solution to(HE). Hence, the general solution to (HE) is

Second order ODEs

The homogeneous case

and y2 = e(i)x = ex eix .

Let

and the general solution to (HE) is

y = Aex + Bxex ,

54

We want to write the general solution as a real-valued function.

and y2 = e2 x

y = Ae1 x + Be2 x ,

The homogeneous case

Case 3: If the characteristic equation (16) has two complex roots1 = + i and 2 = i, then

Case 1: If the characteristic equation (16) has two distinct realsolutions 1 and 2 , theny1 = e1 x

Second order ODEs

+ eix= ex cos x2 eix= ex sin x.2

Due to Lemma 32, the functions z1 and z2 are two solutions of(HE). They are linearly independent; hence, the general solutionto (HE) is

y = ex A cos x + B sin x , A, B R.

A, B R.55

Second order ODEs

The homogeneous case

56

Summary

Example 35Solve the IVPy 4y 5y = 0,

Characteristic equation2 + a + b = 01 6= 2 R1 = 2 (= )1 = + i, 2 = i

Second order ODEs

y(0) = 2, y (0) = 10.

Second order ODEy + ay + by = 0y = Ae1 x + Be2 xy = Aex + Bxex

y = ex A cos x + B sin x

The homogeneous case

57

Example 36

Second order ODEs

The homogeneous case

58

Example 37

Solve the IVP

Solve the ODE y 2y + 5y = 0.

y + 6y + 9y = 0,

Second order ODEs

y(0) = 0, y (0) = 5.

The homogeneous case

59

Second order ODEs

The homogeneous case

60

The non-homogeneous case

Example 40Solve y 5y + 6y = 6x + 7.

Lemma 38If y1 and y2 are solutions of (NE) then y1 y2 is a solution of (HE).Proof: Exercise!Lemma 39The general solution of (NE) is given by y = yh + yp where yh is thegeneral solution of (HE) and yp is a particular solution of (NE).We have learnt how to find yh .How to find a particular solution yp of (NE)?

Second order ODEs

The non-homogeneous case

61

Method of undetermined coefficients

Second order ODEs

The non-homogeneous case

62

Example 41If an (NE) has right-hand sidef (x) = xe2x + 4x cos(5x)

RHS f (x) of (NE)P(x) (polynomial of degree n)P(x)ekxP(x)ekx cos(x)P(x)ekx sin(x)

Guess for particular solution ypQ(x) (polynomial of degree n)Q(x)ekx

ekx Q1 (x) cos(x) + Q2 (x) sin(x)ekx Q1 (x) cos(x) + Q2 (x) sin(x)

andyh = (A + Bx)e2x ,what is a guess for yp ?

NoteIf any term of the guess for yp is part of yh , then multiply that termby x.If the new guess is still part of yh , multiply by x again.

Second order ODEs

The non-homogeneous case

63

Second order ODEs

The non-homogeneous case

64

Example 42Solve y + y = x 2 + x.

Second order ODEs

The non-homogeneous case

65

Second order ODEs

The non-homogeneous case

66

67

Second order ODEs

The non-homogeneous case

68

Example 43Solve y + 4y + 4y = e2x .

Second order ODEs

The non-homogeneous case

Example 44Solve y + y = cos x such that y(0) = 3 and y (0) = 0.

Second order ODEs

The non-homogeneous case

69

Second order ODEs

The non-homogeneous case

70

Vibrations and resonance

Example 45

Simple harmonic motion

If the object is pulled downwards from its equilibrium position by adistance of 4 units and then released from rest, find x(t) when t 0.

Suppose that a spring is mounted to a fixed pointP and that an object of mass m is suspendedfrom the spring. Let x denote the verticaldisplacement from the equilibrium position of theobject, taking x to be positive if it lies above theequilibrium position.It can be shown (by using Newtons second lawof motion and Hookes law) that

The displacement x(t) is the solution to the following IVP:x (t) + 2 x(t) = 0,

So the general solution is

x(t) = A cos t + B sin t,where A and B are constants.A = 4. Since

x (t) + 2 x(t) = 0

Modelling with second order ODEs

x (0) = 0.

2 + 2 = 0,which has two complex solutions = i.

x

where is a positive constant depending only onm and the stiffness of the spring. We ignoregravity, friction, and air resistance.Second order ODEs

x(0) = 4,

The characteristic equation is

The initial condition x(0) = 4 gives

x (t) = A sin t + B cos t,

71

the initial condition x (0) = 0 gives B = 0.B = 0. Therefore x(t) = 4 cos t.Second order ODEs

Modelling with second order ODEs

Since > 0 we have72

Step 2: To find a particular solution yp to the given equation weconsider two different cases.Case 1: 6= . We look for a particular solution in the form

Example 46 (Vibrating support)If the point P vibrates up and down and thedisplacement is given by 2 sin t, then it can beshown that x obeys the differential equationx (t) + 2 x(t) = 2 sin t.

sin t

yp = C cos t + D sin t.

x

By substituting into the given equation we obtain

2 2 C cos t + 2 2 D sin t = 2 sin t.

Describe the motion of the object, given thatx(0) = 4 and x (0) = 0.

Since 2 2 6= 0 we deduce C = 0 and D =

Step 1: The general solution to the corresponding homogeneousequation is yh = A cos t + B sin t; see Example 45.

Second order ODEs

Modelling with second order ODEs

Hence

73

Case 2: = . We look for a particular solution in the form

2 sin typ = 2. 2

Second order ODEs

74

y = yh + yp = A cos t + B sin t + yp .

By substituting into the given equation we obtain

We impose the initial conditions to find A and B.Case 1: 6= . Then

2C sin t + 2D cos t = 2 sin t.

2sin t, 2 22cos t.y = A sin t + B cos t + 2 2y = A cos t + B sin t +

So D = 0 and C = 1/. Hencet cos typ = .

Modelling with second order ODEs

Modelling with second order ODEs

Step 3: The general solution to the given equation is

yp = Ct cos t + Dt sin t.

Second order ODEs

2. 2 2

75

Second order ODEs

Modelling with second order ODEs

76

Case 2: = . Then

Since y(0) = 4 the first equation gives A = 4.Since y (0) = 0 the second equation gives

1t cos t,1y = A sin t + B cos t cos t + t sin t.y = A cos t + B sin t

2B + 2=0 2orB=Hencey = 4 cos t

Since y(0) = 4 the first equation gives A = 4.11Since y (0) = 0 the second equation gives B = 0 or B = 2 .Hence

1t11cos t.y = 4 cos t+ 2 sin t t cos t = 2 sin t 4 +

2.( 2 2 )

22sin t + 2sin t.( 2 2 ) 2

This is a stable oscillation.

Second order ODEs

This is a resonance. As t increases, the amplitude of cos t growswithout bound and the system is unstable.

Modelling with second order ODEs

77

Application Car suspension and shock absorbersm

Modelling with second order ODEs

y (t) + y (t) + 2 y(t) = 0, : friction, : natural frequency

y=0

Characteristic equation:2 + + 2 = 0,

shockabsorber

spring

=

y (t) = Ae+ t + Be t ,

y (t) = e 2 t (A cos t + B sin t) ,

d(y(t) a(t))dtdt 2my (t) + cy (t) + ky(t) = ca (t) + ka(t)=: f (t).m

Second order ODEs

= k(y(t) a(t)) c

Modelling with second order ODEs

< 0.

Underdamped case: < 2

road surface

d 2 y(t)

2 4 2.2

Overdamped case: > 2

a(t)

wheel

78

The free but damped oscillator

y(t)mass

Second order ODEs

=

r

2

24

Critically damped case: = 2y (t) = Ae 2 t + Bte 2 t .

79

Second order ODEs

Modelling with second order ODEs

80

The forced and damped oscillator

Critical damping is the fastest way to return to equilibrium without oscillations(overshooting). Car shock absorbers are designed to achieve criticaldamping.

y (t) + y (t) + 2 y(t) = cos t The preceding analysis shows that y = yH + yP yP as t .

1.0

0.8

Particular solution

0.6

yP = a sin t + b cos t

underdampedcritically dampedoverdamped

y(t)

0.4

with a =

,2 + 2 2

b=

,2 + 2 2

where = 2 2 .

0.2

Amplitude:

02

4

6

8

10

t

Second order ODEs

Modelling with second order ODEs

81

Second order ODEs

AMP =

p

a2 + b 2 =

12 + 2 2

Modelling with second order ODEs

82

Linear ODEs and Linear AlgebraLet C(I) denote the space of all continuous functions y : I R,where I is an interval in R.For n = 1, 2, . . . , let C n (I) denote the space of all n-timecontinuously differentiable functions y : I R, i.e., y, y , y , . . . ,y (n) are continuous functions defined on I.Let a0 , a1 , . . . , an1 be continuous functions. We define the mapT that maps a function y in C n (I) into a function in C(I) by (seeDefinition 5)

Maximum amplitude: For what forcing frequency (i.e., ) is the steadystate amplitude at a maximum?dd AMP= 0 (2 + 2 2 ) = 0dd22= 2 = max= 2 211.= AMPmax = q2 2 4

d n1 yd nyd n2 ydy+an1 (x) n1 +an2 (x) n2 +. . .+a1 (x) +a0 (x)y.dx ndxdxdxT is called a transformation or an operator.For example:T (y) =

Conclusion: If is small then max and AMPmax is large. This isresonance.

T (y) = y + x 2 y,T (y) = y + ay + bySecond order ODEs

Modelling with second order ODEs

83

Linear ODEs: a theoretical view

(n = 1)for some fixed a, b R, (n = 2)84

T is a linear operator

Proof.For simplicity we prove only the case T (y) = y + ay + by. For ally1 , y2 C n (I) and R,T (y1 + y2 ) = (y1 + y2 ) + a(y1 + y2 ) + b(y1 + y2 )

Theorem 47

= y1 + y2 + ay1 + ay2 + by1 + by2

The operator T : C n (I) C(I) defined byT (y) =

= (y1 + ay1 + by1 ) + (y2 + ay2 + by2 )

d n2 ydyd nyd n1 y+ an1 (x) n1 + an2 (x) n2 + . . . + a1 (x)+ a0 (x)ydx ndxdxdx

is a linear operator, i.e., for all y1 , y2 C n (I) and R there hold

= T (y1 ) + T (y2 )andT (y1 ) = (y1 ) + a(y1 ) + b(y1 )

T (y1 + y2 ) = T (y1 ) + T (y2 ) and T (y1 ) = T (y1 ).

= (y1 + ay1 + by1 )= T (y1 ).

Linear ODEs: a theoretical view

85

Linear ODEs: a theoretical view

86

ker(T ) and solutions of the homogeneous equation If yh ker(T ) and yp is any solution of (17), then

Recall: The kernel of T is defined by ker(T ) = {y : T (y) = 0}.

T (yh + yp ) = T (yh ) + T (yp ) = T (yp ) = f .So yh + yp is a solution to (17).

Consider for simplicity second order linear ODEs with constantcoefficients only, i.e.,y + ay + by = f .

(17)

In this case,

If y and yp are solutions of (17) thenT (y yp ) = T (y) T (yp ) = f f = 0,

T (y) = y + ay + by.

so that y yp ker(T ). If yh is a solution of the homogeneous equation y + ay + by = 0then T (yh ) = 0 so that yh ker(T ).

It follows that yh := y yp ker(T ). Hence all solutions of (17) areof the form yh + yp .

If y is a solution of (17) then T (y) = f so that f is in the image of T .Linear ODEs: a theoretical view

87

Linear ODEs: a theoretical view

88

Numerical methods for IVPsExample 48The general solution of the first order linear equationy + y/x = x

Consider the IVP y = sin(xy) and y(0) = 0. None of the methodsthat we have presented allow you to solve this equation.

is y = C/x + x 2 /3; see Example 20.

In many practical situations, you may find that yo dont even havean analytic expression for y , but rather just a black box whichallows you to dertermine y numerically at any given (x, y) pointthat you enter.

Let T (y) = y + y/x, yh = C/x, and yp = x 2 /3. ThenT (yh ) = 0 and T (yp ) = x.The general solution to the corresponding homogeneous equationy + y/x = 0 is yh = C/x.

In situations like these, you can apply numerical methods toapproximate the solutions to such an IVP.

A particular solution to the non-homogeneous equation isyp = x 2 /3.

Linear ODEs: a theoretical view

89

Eulers methodConsider the IVP

90

Example 49(y = f (x, y),y(x0 ) = y0 .

Use Eulers method with a step size of h = 0.1 to approximate thesolution of the IVPy = x + y, y(0) = 1.

x > x0 ,

(Note: This IVP can be solved exactly, and the exact solution isy(x) = 2ex 1 x.)With h = 0.1, we have

For h > 0 sufficiently small (which is called the step size) we have

y(x0 + h) y(x0 ) + hy (x0 ) = y(x0 ) + hf (x0 , y0 ).

x0 = 0,

For k = 1, 2, . . . , let xk = x0 + kh. Defining

x2 = 0.2, y2 = y1 + h(t1 + y1 ) = 1.1 + 0.1(0.1 + 1.1) = 1.22x3 = 0.3, y3 = y2 + h(t2 + y2 ) = 1.22 + 0.1(0.2 + 1.22) = 1.362

the above equation shows that y(x1 ) y1 .If we define iterativelyyk +1 = yk + hf (xk , yk ),

y0 = 1

x1 = 0.1, y1 = y0 + h(t0 + y0 ) = 1 + 0.1(0 + 1) = 1.1

y1 = y0 + hf (x0 , y0 ),

xn00.10.20.3

k = 0, 1, 2, . . . ,

then we can approximate y(xk ) by yk . This approach is calledEulers method.Numerical methods

Numerical methods

91

Numerical methods

y (xn )11.11034181.24280551.3997176

yn11.11.221.362

y (xn ) yn00.01034180.02280550.0377176

Rel. error0%0.94 %1.87 %2.77 %92

M ATLAB function file Euler.m

M ATLAB function file Euler.m (cont.)

function [x,y] = Euler(fstring,a,b,y0,N)

h = (b-a)/N;x = a:h:b;d = length(y0);y0 = y0(:); % convert y0 to a column array

%%%%%%%%%%%%%

Euler(fstring,y0,N) solves the odey(x) = f(x,y) for a < x < b,with initial condition y(a) = y0.

y = zeros(d,N+1);y(:,1) = y0;for n = 2:N+1y(:,n) = y(:,n-1) + h * fstring(x(n-1),y(:,n-1));end

Inputs:fstring: name of the function that computes f(x,y).N: number of intervals in the grid.Outputs:x: row vector of length N+1x(n) = a + (n-1) h, h = (b-a)/N.

To use this function you need a script file, say Eg50.m as on the nextpage.

y: row vector of length N+1 containing the approx.value y(n) of the exact solution y(x(n)).

To run this script, on the M ATLAB command window type>> Eg50

Numerical methods

93

Numerical methods

94

M ATLAB script file Eg50.m that uses function Euler.m

Errors

% Solve y = 1/(1+x^2) - 2y^2 on [0,1] with y(0) = 0.

As a rough rule of thumb, the absolute error in Eulers method isproportional to the step size. So if we were to halve the step size wewould expect to roughly halve these errors.

a = 0; b = 1; y0 = 0; N = 20;func = @(x,y) 1./(1+x.^2) - 2 * y.^2;y_exact = @(x) x ./ (1 + x.^2);

Example 50Suppose we use Eulers method to solve the following problem

[t,y] = Euler(func,a,b,y0,N);xplot = linspace(a,b);plot(t,y,*-r,xplot,y_exact(xplot),b)

1y = 2y 2 ,1 + x2y(0) = 0,

info = [N = , num2str(N)];text(0.05,2.5,char(info))

which has as exact solution

xlabel(x), ylabel(y)title(Example 50)legend(y_n, y(x), location,NorthWest)print -depsc Example50.epsNumerical methods

0 < x < 1,

y(x) =

x.1 + x2

The approximate solutions yn , together with the errorsEn := y(xn ) yn , are given in the following table.95

Numerical methods

96

Improved Euler method

Example 50 (cont.)h = 0.2

h = 0.1

xn0.20000.40000.60000.80001.00000.10000.20000.30000.40000.50000.60000.70000.80000.90001.0000

y(xn )0.19230.34480.44120.48780.50000.09900.19230.27520.34480.40000.44120.46980.48780.49720.5000

yn0.20000.37630.49210.54230.54660.10000.19700.28540.36090.42100.46560.49570.51370.52190.5227

En-0.0077-0.0315-0.0509-0.0545-0.0466-0.0010-0.0047-0.0102-0.0160-0.0210-0.0244-0.0259-0.0259-0.0247-0.0227

maxn |En |

Eulers method to compute y1 can be derived as follows. It isknown thatZ x1y(x1 ) = y(x0 ) +y (x) dx.x0

use the left-hand endpoint rule to approximate the integralRIf xwe1x0 y (x) dx, i.e., if we approximate y (x) by y (x0 ) for allx [x0 , x1 ] then (noting that h = x1 x0 )

0.0545

y(x1 ) y0 + hy (x0 ) = y0 + hf (x0 , y0 ) =: y1 .

The approximation will be more accurate if we approximate theintegral by the trapezoidal ruleZ x1y (x0 ) + y (x1 )y (x) dx h.2x0This leads to an improved formula to compute y1 :hhy1 = [y (x0 ) + y (x1 )] = [f (x0 , y0 ) + f (x1 , y1 )].22

0.0259

Numerical methods

97

Improved Euler method (cont.)

Numerical methods

Example 51We solve the same problem as in Example 50 with the Improved Eulermethod. In the following table note the convergence of order O(h) forEulers method and order O(h2 ) for the Improved Euler method.(E)(H)(En : absolute error by Eulers method; En : absolute error by theImproved Euler method.)

Since we dont know y1 on the right hand side of the aboveformula, we approximate it by its Euler approximation:u1 = y0 + hf (x0 , y0 )hy1 = [f (x0 , y0 ) + f (x1 , u1 )].2

h = 0.2

Improved Euler algorithm: For k = 0, 1, 2, . . . ,xk +1 = xk + hh = 0.1

uk +1 = yk + hf (xk , yk )hyk +1 = [f (xk , yk ) + f (xk +1 , uk +1 )].2This method is also called Heuns method.Numerical methods

98

99

tn0.20000.40000.60000.80001.00000.1000...0.70000.80000.90001.0000

Numerical methods

(E)

En-0.0077-0.0315-0.0509-0.0545-0.0466-0.0010...-0.0259-0.0259-0.0247-0.0227

(E)

maxn |En |

0.0545

0.0259

(H)

En0.00420.00820.01050.01040.00890.0005...0.00230.00220.00210.0019

(H)

maxn |En |

0.0105

0.0023100

M ATLAB function Heum.m for the Improved Eulermethod

M ATLAB function Heum.m for the Improved Eulermethod (cont.)

function [t,y] = Heun(fstring, a, b, y0, N)% Heun(fstring, y0, N) solves the ode%y(t) = f(t,y) for a < t < b,% with initial condition y(a) = y0.%% Inputs:%fstring: function that compute f(t,y)%N: number of intervals% Outputs:%t: row vector of length N+1 containing the points%t(n) = a + (n-1)h, h = (b-a)/N.%y: row vector of length N+1 containing the approx.%values y(n) of the exact solution y(t(n)).

h = (b-a) / N;t = a:h:b;d = length(y0);y0 = y0(:);y = zeros(N,d);y(1,:) = y0;for n = 2:N+1v = y(n-1) + h * feval(fstring, t(n-1), y(n-1));y(n) = y(n-1) + ( h / 2 ) * ...( feval(fstring, t(n-1), y(n-1)) + ...feval(fstring, t(n), v) );end

Numerical methods

101

Better methods?

More accurate methods can be derived, e.g. Runge-Kutta methods.These will be learnt in MATH2301.

Numerical methods

103

Numerical methods

102