unit17.mws

ORDINARY DIFFERENTIAL EQUATIONS POWERTOOL

Unit 17 -- Shooting Method

Prof. Douglas B. Meade

Industrial Mathematics Institute

Department of Mathematics

University of South Carolina

Columbia, SC 29208

URL: http://www.math.sc.edu/~meade/

E-mail: meade@math.sc.edu

Copyright © 2001 by Douglas B. Meade

All rights reserved

-------------------------------------------------------------------

>

Outline of Unit 17

>

Initialization

> restart;

> with( DEtools ):

> with( plots ):

> with( linalg ):

Warning, the name changecoords has been redefined

Warning, the name adjoint has been redefined

Warning, the protected names norm and trace have been redefined and unprotected

>

17.A Overview of the Shooting Method

The basic idea behind the shooting method is to convert a boundary value problem (BVP) into an initial value problem (IVP). One parameter is introduced for each missing initial condition. The boundary conditions that are not initial conditions serve as the constraints to determine appropriate values for the parameters. That is, given an initial guess for the parameters, an iterative solver is used to find values of the parameters that produce (approximate) solutions that satisfy the boundary conditions.

The shooting method is quite general. Here it will be demonstrated only for two second-order linear two-point boundary value problems of the form

Diff(y,`$`(x,2))+p(x)*Diff(y,x)+q(x)*y = f(x)

y(a) = r

y(b) = s .

The IVP that will be used as the basis for the shooting method is

Diff(y,`$`(x,2))+p(x)*Diff(y,x)+q(x)*y = f(x)

y(a) = r

eval(Diff(y,x),x = a) = alpha

where alpha is the unknown parameter. Call the solution to this IVP y^alpha . The goal is to find alpha such that y^alpha ( b ) = s . To accomplish this, define a Maple procedure that accepts the IVP with a specific value for alpha , the unknown function, and the value of b and returns the value of y^alpha ( b )

> Yb := ( ivp, fn, b ) ->

> eval( fn, dsolve( ivp, fn, type=numeric )(b) );

Yb := proc (ivp, fn, b) options operator, arrow; ev...

>

and then use, e.g. , the Secant Method to solve for the value of alpha for which y^alpha ( b ) - s = 0.

A more sophisticated and general implementation of the Shooting Method is available from the Maple Applications Center .

>

17.B Example 1

Consider the BVP

> ode1 := diff( y(x), x$2 ) + 2 * diff( y(x), x ) - 10 * y(x) = 7*exp(-x) + 4;

> bc1 := y(0)=2, y(1)=-5;

ode1 := diff(y(x),`$`(x,2))+2*diff(y(x),x)-10*y(x) ...

bc1 := y(0) = 2, y(1) = -5

>

with boundary conditions specified at the points

> a := 0;

> b := 1;

a := 0

b := 1

>

The corresponding IVP has initial conditions

> ic1 := bc1[1], D(y)(a)=alpha;

ic1 := y(0) = 2, D(y)(0) = alpha

>

where alpha is to be chosen to make

> constraint := lhs(bc1[2])-rhs(bc1[2]):

> constraint = 0;

y(1)+5 = 0

>

Here is an implementation of the Secant Method :

> a0 := 0:

> y0 := eval( constraint, y(b)=Yb( eval( {ode1,ic1}, alpha=a0 ), y(x), b ) ):

> a1 := 1:

> y1 := eval( constraint, y(b)=Yb( eval( {ode1,ic1}, alpha=a1 ), y(x), b ) ):

> while fnormal(y1-y0)<>0 do

> z := solve( y1 = (y1-y0)/(a1-a0)*(a1-x), x );

> a0, a1 := a1, z;

> y0, y1 := y1, eval( constraint, y(b)=Yb( eval( {ode1,ic1}, alpha=z ), y(x), b ) );

> end do:

> alpha_opt1 := z;

alpha_opt1 := -15.35641162

>

The shooting method solution is the solution to the IVP corresponding to this optimal choice of the parameter :

> shoot_sol1 := dsolve( eval( {ode1,ic1}, alpha=alpha_opt1 ), y(x) );

shoot_sol1 := y(x) = -2/5-7/11*exp(-x)+(167/110-647...

>

Not surprisingly, because of the simple nature of this example, Maple is able to determine the exact solution to this problem.

> infolevel[dsolve] := 3:

> exact_sol1 := combine(dsolve( { ode1, bc1 }, y(x) ));

> infolevel[dsolve] := 0:

Methods for second order ODEs:

Trying to isolate the derivative d^2y/dx^2...

Successful isolation of d^2y/dx^2

-> Trying classification methods

trying a quadrature

trying high order exact linear fully integrable

trying differential order: 2; linear nonhomogeneous with symmetry [0,1]

trying 2nd order linear exact nonhomogeneous

trying a double symmetry of the form [xi=0, eta=F(x)]

trying linear constant coefficient

linear constant coefficient successful

exact_sol1 := y(x) = -2/5-7/11*exp(-x)+(167/55*exp(...
exact_sol1 := y(x) = -2/5-7/11*exp(-x)+(167/55*exp(...

>

To compare the solutions, plot the exact and shooting solutions

> plot( [rhs(exact_sol1),rhs(shoot_sol1)], x=0..1, color=[BLACK,RED],

> thickness=[1,3], legend=['exact','shooting'] );

[Maple Plot]

>

Note that the value of the shooting method solution at the right-hand boundary point is

> evalf( eval( rhs(shoot_sol1), x=1 ) );

-5.000000005

>

This also shows good agreement between the shooting method and exact solutions.

>

17.C Example 2

Consider the BVP

> ode2 := x^2 * diff( y(x), x$2 ) + x * diff( y(x), x ) + 4 * y(x) = -2*x + 7;

> bc2 := y(1)=7, y(4)=-1;

ode2 := x^2*diff(y(x),`$`(x,2))+x*diff(y(x),x)+4*y(...

bc2 := y(1) = 7, y(4) = -1

>

The boundary conditions are given at

> a := 1;

> b := 4;

a := 1

b := 4

>

The corresponding IVP has initial conditions

> ic2 := bc2[1], D(y)(a)=alpha;

ic2 := y(1) = 7, D(y)(1) = alpha

>

where alpha is to be chosen to make

> constraint := lhs(bc2[2])-rhs(bc2[2]):

> constraint = 0;

y(4)+1 = 0

>

Here is an implementation of the Secant Method :

> a0 := 0:

> y0 := eval( constraint, y(b)=Yb( eval( {ode2,ic2}, alpha=a0 ), y(x), b ) ):

> a1 := 1:

> y1 := eval( constraint, y(b)=Yb( eval( {ode2,ic2}, alpha=a1 ), y(x), b ) ):

> while fnormal(y1-y0)<>0 do

> z := solve( y1 = (y1-y0)/(a1-a0)*(a1-x), x );

> a0, a1 := a1, z;

> y0, y1 := y1, eval( constraint, y(b)=Yb( eval( {ode2,ic2}, alpha=z ), y(x), b ) );

> end do:

> alpha_opt2 := z;

alpha_opt2 := 22.44355527

>

The shooting method solution is the solution to the IVP corresponding to this optimal choice of the parameter.

> shoot_sol2 := dsolve( eval( {ode2,ic2}, alpha=alpha_opt2 ), y(x) );

shoot_sol2 := y(x) = 7/4-2/5*x+2284355527/200000000...

>

Again, because of the simple nature of this example, Maple is able to determine the exact solution to this problem.

> exact_sol2 := combine(dsolve( { ode2, bc2 }, y(x) ));

exact_sol2 := y(x) = 1/20*(35*sin(4*ln(2))-8*x*sin(...

>

To compare the solutions, plot the exact and shooting solutions

> plot( [rhs(exact_sol2),rhs(shoot_sol2)], x=1..4,

> color=[BLACK,RED],thickness=[1,3],

> legend=['exact','shooting'] );

[Maple Plot]

>

Note also that the value of the shooting method solution at the right-hand boundary point is

> evalf( eval( rhs(shoot_sol2), x=1 ) );

7.

>

This also shows good agreement between the shooting method and exact solutions.

>

[Back to ODE Powertool Table of Contents]

>