The Shooting Method for Boundary-value Problems

Slides:



Advertisements
Similar presentations
M. Dumbser 1 / 23 Analisi Numerica Università degli Studi di Trento Dipartimento dIngegneria Civile ed Ambientale Dr.-Ing. Michael Dumbser Lecture on Numerical.
Advertisements

Boyce/DiPrima 9th ed, Ch 2.4: Differences Between Linear and Nonlinear Equations Elementary Differential Equations and Boundary Value Problems, 9th edition,
Differentiation and Richardson Extrapolation
Topics in Applied Mathematics Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada.
3 DERIVATIVES.
A second order ordinary differential equation has the general form
Ch 5.2: Series Solutions Near an Ordinary Point, Part I
Ch 7.1: Introduction to Systems of First Order Linear Equations
Systems of Non-Linear Equations
Boundary-value Problems and Finite-difference Equations Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University.
FP1: Chapter 2 Numerical Solutions of Equations
Laplace’s Equation in 2 and 3 Dimensions Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Differential Equations and Boundary Value Problems
Heat-conduction/Diffusion Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Boyce/DiPrima 9 th ed, Ch 3.1: 2 nd Order Linear Homogeneous Equations-Constant Coefficients Elementary Differential Equations and Boundary Value Problems,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
MATH 212 NE 217 Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada Copyright © 2011.
The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Solving Non-Linear Equations (Root Finding)
Fixed-Point Iteration Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Copyright © 2007 by Douglas Wilhelm.
MATH 212 NE 217 Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada Copyright © 2011.
Simpson Rule For Integration.
The Crank-Nicolson Method and Insulated Boundaries
Fin500J Topic 6Fall 2010 Olin Business School 1 Fin500J: Mathematical Foundations in Finance Topic 6: Ordinary Differential Equations Philip H. Dybvig.
MATH 212 NE 217 Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada Copyright © 2011.
Numerical Methods Applications of Loops: The power of MATLAB Mathematics + Coding 1.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
3 DERIVATIVES. In this section, we will learn about: Differentiating composite functions using the Chain Rule. DERIVATIVES 3.5 The Chain Rule.
Copyleft  2005 by Media Lab Ordinary Differential Equations Boundary Value Problems.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
MA/CS 375 Fall MA/CS 375 Fall 2002 Lecture 31.
Boundary-Value Problems Boundary-value problems are those where conditions are not known at a single point but rather are given at different values of.
MATH 212 NE 217 Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada Copyright © 2011.
Chapter 3 Roots of Equations. Objectives Understanding what roots problems are and where they occur in engineering and science Knowing how to determine.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Numerical Methods for Engineering MECN 3500
Problems with Floating-Point Representations Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Copyright.
Boundary Value Problems l Up to this point we have solved differential equations that have all of their initial conditions specified. l There is another.
Numerical Methods.
CHAPTER 3 NUMERICAL METHODS
Newton’s Method, Root Finding with MATLAB and Excel
The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada.
Solving Non-Linear Equations (Root Finding)
Numerical Methods Solution of Equation.
Iteration Methods “Mini-Lecture” on a method to solve problems by iteration Ch. 4: (Nonlinear Oscillations & Chaos). Some nonlinear problems are solved.
MATH 212 NE 217 Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada Copyright © 2011.
Recap Cubic Spline Interpolation Multidimensional Interpolation Curve Fitting Linear Regression Polynomial Regression The Polyval Function The Interactive.
Lecture 21 MA471 Fall 03. Recall Jacobi Smoothing We recall that the relaxed Jacobi scheme: Smooths out the highest frequency modes fastest.
Interpolation Search Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada.
Interpolating Solutions to IVPs Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Chapter 27.
1 Chapter 1 Introduction to Differential Equations 1.1 Introduction The mathematical formulation problems in engineering and science usually leads to equations.
Boundary-Value Problems in Rectangular Coordinates
Dr. Mujahed AlDhaifallah ( Term 342)
MATH 212 NE 217 Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada Copyright © 2011.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Linear Systems Numerical Methods. 2 Jacobi Iterative Method Choose an initial guess (i.e. all zeros) and Iterate until the equality is satisfied. No guarantee.
Lecture 39 Numerical Analysis. Chapter 7 Ordinary Differential Equations.
The formulae for the roots of a 3rd degree polynomial are given below
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 6 - Chapters 22 and 23.
Finding zeros (also called roots) of a function Overview: Define the problem Methods of solution Graphical Newton’s Bisection Secant.
1 M 277 (60 h) Mathematics for Computer Sciences Bibliography  Discrete Mathematics and its applications, Kenneth H. Rosen  Numerical Analysis, Richard.
Announcements Topics: Work On:
Numerical Methods and Analysis
Solution of Equations by Iteration
Boundary-value problems and Finite-difference equations
Laplace’s Equation in 2 and 3 Dimensions
Copyright © Cengage Learning. All rights reserved.
MATH 1910 Chapter 3 Section 8 Newton’s Method.
Presentation transcript:

The Shooting Method for Boundary-value Problems Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada ece.uwaterloo.ca dwharder@alumni.uwaterloo.ca © 2012 by Douglas Wilhelm Harder. Some rights reserved.

Outline This topic to approximating boundary-value problems The Shooting Method for Boundary-value Problems Outline This topic to approximating boundary-value problems We will describe boundary-value problems (BVPs) We will look at solutions with linear ordinary differential equations (ODEs) We will consider solutions for non-linear ODEs This will require successive approximations using the secant method

Outcomes Based Learning Objectives The Shooting Method for Boundary-value Problems Outcomes Based Learning Objectives By the end of this laboratory, you will understand: Boundary-value problems (BVPs) How to use an initial-value problem (IVP) solver to approximate solutions to BVPs The solution to linear BVPs The application of the secant method to solve non-linear BVPs

The Shooting Method for Boundary-value Problems Using Matlab These methods assume that the student has written the initial-value problem solver pd45 with the signature dp45( f, x_rng, u0, h, eps_abs ) which uses the Dormand-Prince method If this routine is not available, you are welcome to use the built-in Matlab routine ode45 which has the similar signature ode45( f, x_rng, u0 )

The Shooting Method for Boundary-value Problems 2nd-order ODEs A boundary-value problem in one dimension is any 2nd-order ODE F(x, u(x), u(1)(x), u(2)(x)) = 0 with two constraints u(a) = ua u(b) = ub In general, we will look at functions of the form u(2)(x) = f(x, u(x), u(1)(x))

The Shooting Method for Boundary-value Problems 2nd-order ODEs Consider the corresponding initial-value problem for this 2nd-order ODE F(x, u(x), u(1)(x), u(2)(x)) = 0 with two constraints u(a) = ua u(1)(a) = ua(1) Here we specify the slope at the left-hand point x = a

2nd-order ODEs Thus, a boundary-value problem could be restated as: The Shooting Method for Boundary-value Problems 2nd-order ODEs Thus, a boundary-value problem could be restated as: Given one initial condition u(a) = ua, what slope is required at that initial point so that the solution to that initial condition passes through the point (b, ub)? (b, ub) (a, ua)

2nd-order ODEs We will consider two possible cases: The Shooting Method for Boundary-value Problems 2nd-order ODEs We will consider two possible cases: When the ODE is linear, and When it is not (b, ub) (a, ua)

The Shooting Method for Boundary-value Problems 2nd-order Linear ODEs A 2nd-order ODE is said to be linear if it can be written as u(2)(x) + q(x) u(1)(x) + r(x) u(x) = g(x) or u(2)(x) = g(x) – q(x) u(1)(x) – r(x) u(x) We will also consider the corresponding homogenous LODE: u(2)(x) + q(x) u(1)(x) + r(x) u(x) = 0 u(2)(x) = –q(x) u(1)(x) – r(x) u(x)

The Shooting Method for Boundary-value Problems 2nd-order Linear ODEs To demonstrate 2nd-order LODEs, we will consider the example The corresponding homogeneous LODE is the

The Shooting Method for Boundary-value Problems 2nd-order Linear ODEs Recall that if ug(x) is a solution to a 2nd-order LODE and u0(x) is a solution to the corresponding homogenous LODE, then ug(x) + c·u0(x) is also a solution the LODE g(x)

The Shooting Method for Boundary-value Problems 2nd-order Linear ODEs Suppose we have redefine a boundary-value problem in terms of two IVPs, the first on the LODE with constraints and the second on the homogenous LODE with constraints Let ug(x) and u0(x) be the solutions, respectively

The Shooting Method for Boundary-value Problems 2nd-order Linear ODEs For example, given the LODE from before, we create the two IVPs The plots of the solutions: (b, ub) ug(x) (a, ua) u0(x)

The Shooting Method for Boundary-value Problems 2nd-order Linear ODEs Having found these two solutions, ug(x) and u0(x), we now want to find a linear combination of these two such that it satisfies the second boundary value For example, here we see ug(x), ug(x) + u0(x), and ug(x) – u0(x) It seems ug(x) + 2u0(x) will pass close to the second boundary point (b, ub) ug(x) + u0(x) (a, ua) ug(x) ug(x) – u0(x)

The Shooting Method for Boundary-value Problems 2nd-order Linear ODEs We want to find the appropriate linear combination to match our second boundary condition First, we note We want Solving this for c yields

The Shooting Method for Boundary-value Problems 2nd-order Linear ODEs Easy enough; however, recall that we must find ug(x) and u0(x) but if we use dp45, the step sizes may be different… Solution: define a system of two uncoupled equations and unknowns and solve them simultaneously u(2)(x) = g(x) – q(x) u(1)(x) – r(x) u(x) u(2)(x) = 0 – q(x) u(1)(x) – r(x) u(x)

The Shooting Method for Boundary-value Problems 2nd-order Linear ODEs Using our techniques from Laboratory 5, we can write this as a system of IVPs: w1(1)(x) = w2 (x) w2(1)(x) = g(x) – q(x) w2(x) – r(x) w1(x) w3(1)(x) = w4 (x) w4(1)(x) = 0 – q(x) w4(x) – r(x) w3(x) w1(a) = ua w2(a) = 0 w3(a) = 0 w4(a) = 1 ug(x) = w1(x) ug(1)(x) = w2(x) u0(x) = w3(x) u0(1)(x) = w4(x)

2nd-order Linear ODEs For example, consider the boundary-value problem The Shooting Method for Boundary-value Problems 2nd-order Linear ODEs For example, consider the boundary-value problem The Matlab function would be: function [dw] = f6a( x, w ) dw = [w(2); 1 - sin(x)*w(2) - w(1); w(4); 0 - sin(x)*w(4) - w(3)]; end with the initial conditions [u_a, 0, 0, 1]'

The Shooting Method for Boundary-value Problems 2nd-order Linear ODEs For our example, we would run the following code: a = 2; b = 3; u_a = 1.5; u_b = 2.5; [x6a, u6a] = dp45( @f6a, [a, b], [u_a 0 0 1]', 0.01, 1e-8 ); c6a = (u_b - u6a(1, end))/u6a(3, end) c6a = 1.991628911663175 u6a_soln = u6a(1, :) + c6a*u6a(3, :); plot( x6a, u6a_soln, 'r' ) ylim( [0, 2.5] ) u6a_soln(1) ans = 1.500000000000000 u6a_soln(end) 2.500000000000000

2nd-order Linear ODEs Maple can find an answer, but it’s not nice… The Shooting Method for Boundary-value Problems 2nd-order Linear ODEs Maple can find an answer, but it’s not nice… > a := 2; b := 3; u_a := 1.5; u_b := 2.5; > dsolve( {(D@@2)(u)(x) + sin(x)*D(u)(x) + u(x) = 1, u(a)=u_a, u(b)=u_b} );

The Shooting Method for Boundary-value Problems 2nd-order Linear ODEs It takes Maple about two minute to plot the same figure Note: this is not an issue with Maple—it is giving you the exact solution and not a numeric approximation

2nd-order Linear ODEs: Example The Shooting Method for Boundary-value Problems 2nd-order Linear ODEs: Example For example, consider the boundary-value problem u(2)(x) + 4 u(1)(x) + 7x u(x) = sin(x) u(2) = 1.5 u(3) = 2.5 The Matlab function would be: function [dw] = f6b( x, w ) dw = [w(2); sin(x) - 4*w(2) - 7*x*w(1); w(4); 0 - 4*w(4) - 7*x*w(3)]; end

2nd-order Linear ODEs: Example The Shooting Method for Boundary-value Problems 2nd-order Linear ODEs: Example For example, consider a = 2; b = 3; u_a = 1.5; u_b = 2.5; [x6b, u6b] = dp45( @f6b, [a, b], [u_a 0 0 1]', 0.01, 1e-4 ); u6b_soln = u6b(1,:) + (u_b - u6b(1,end))/u6b(3,end)*u6b(3,:); plot( x6b, u6b_soln, 'o-' ); grid

2nd-order Linear ODEs: Example The Shooting Method for Boundary-value Problems 2nd-order Linear ODEs: Example Maple can find an answer, but it’s not nice… > a := 2; b := 3; u_a := 1.5; u_b := 2.5; > dsolve( {(D@@2)(u)(x) + 4*D(u)(x) + 7*x*u(x) = sin(x), u(a) = u_a, u(b) = u_b}, u(x) );

2nd-order Linear ODEs: Example The Shooting Method for Boundary-value Problems 2nd-order Linear ODEs: Example Comparing the results with Maple’s plot, we see they are similar

2nd-order Linear ODEs: Example The Shooting Method for Boundary-value Problems 2nd-order Linear ODEs: Example If we repeat using b = 4, we get significantly more varying, but still similar, graphs

2nd-order Non-linear ODEs The Shooting Method for Boundary-value Problems 2nd-order Non-linear ODEs What happens if the ODE is not linear? In this case, there is no guarantee that we can find a solution using this simple technique Instead, we will use u(2)(x) = f(x, u(x), u(1)(x)) and let us(x) be the solution to the IVP u(a) = ua u(1) (a) = s Now, define a new function err(s) = us(b) – ub

2nd-order Non-linear ODEs The Shooting Method for Boundary-value Problems 2nd-order Non-linear ODEs When this function has a zero, we have a solution to the boundary-value problem err(s) = us(b) – ub What is err(s) in Matlab? function [du_b] = err_shot( s ) [t_out, u_out] = ... dp45( @f, [a, b], [u_a, s], h, eps_abs ); du_b = u_out(1, end) - u_b; end

2nd-order Non-linear ODEs The Shooting Method for Boundary-value Problems 2nd-order Non-linear ODEs When this function has a zero, we have a solution to the boundary-value problem err(s) = us(b) – ub In reality, however, it will require a number of other parameters: function [du_b] = err_shot(s, f, x_rng, u_bndry, h, eps_abs) u_a = u_bndry(1); u_b = u_bndry(2); [~, u_out] = dp45( f, x_rng, [u_a, s]', h, eps_abs ); du_b = u_out(1, end) - u_b; end

Secant Method We will use the secant method for fining this root: The Shooting Method for Boundary-value Problems Secant Method We will use the secant method for fining this root: Suppose we are trying to find a root of a real-valued function of a real variable err(s) Suppose s1 and s2 are two initial approximations of the root err(s) s2 s1

The Shooting Method for Boundary-value Problems Secant Method We can find a better approximation of the root by finding the interpolating straight line that passes through these points err(s) s2 s1

Secant Method The formula for this new point is err(s) s3 s2 s1 The Shooting Method for Boundary-value Problems Secant Method The formula for this new point is err(s) s3 s2 s1

Secant Method In the first case, we considered linear ODEs The Shooting Method for Boundary-value Problems Secant Method In the first case, we considered linear ODEs Essentially, what we are doing here is asking: Given these two approximations, what would our next approximation be if the ODE was linear? err(s) s3 s2 s1

The Shooting Method for Boundary-value Problems Secant Method Now, suppose we have s2 and s3, the next step is to use these approximations to find the next approximation, s4, and so on... err(s) s3 s2 s1

The Shooting Method for Boundary-value Problems Secant Method Thus, we will continue to iterate, using the secant method at each step... With any iterative numerical method, we must know under what conditions we will: Halt with success, and Indicate a failure to find a solution After all, not all iterative numerical methods converge...

The Shooting Method for Boundary-value Problems Secant Method For the secant method, we must have two approximations, s1 and s2 First, if |err(s1)| < |err(s2)|, we will swap s1 and s2 We’re assuming that s2 is more accurate

Secant Method We will iterate at most Nmax times: The Shooting Method for Boundary-value Problems Secant Method We will iterate at most Nmax times: With each iteration, we will approximate a new point s If |s2 – s| < estep and |err(s)| < eabs, we will assume we are finished and we will return the value s (shooting, however, will take one more step) Otherwise, we will set s1 = s2 and s2 = s If we have iterated Nmax times and not found a solution, we will throw an exception with an appropriate message

The Shooting Method for Boundary-value Problems Normally, the secant method simply returns the slope Your function, shooting, however, will have to return the x- and u-values corresponding to that optimal slope Thus, your last steps before you successfully return will be: [x_out, u_out] = dp45( f, x_rng, [u_bndry(1), s]', h, eps_abs ); return;

The Shooting Method The arguments of are as follows: The Shooting Method for Boundary-value Problems The Shooting Method The arguments of function [x_out, u_out] = shooting( s1, s2, f, x_rng, u_bndry, ... h, eps_abs, eps_step, N_max ) are as follows: s1 and s2 are the two approximations of the slopes f is a function handle for the differential equation: u(2)(x) = f(x, u(x), u(1)(x)) [a, b] is a row vector defining the range on which we are approximating the boundary-value problem [ua, ub] is a row vector defining the boundary conditions: u(a) = ua and u(b) = ub h is the initial step size for the function dp45 eabs is the parameter passed to dp45 and is also the parameter used by the secant method estep is the parameter used by the secant method for the step size Nmax is the parameter used by the secant method to define the maximum number of iterations

The Shooting Method Question: what do we use as initial conditions? The Shooting Method for Boundary-value Problems The Shooting Method Question: what do we use as initial conditions? Answer: as an engineer, you will understand your problem; you should know the expected behaviour around the point x = a In these laboratories, you will be given the initial points In reality, you will understand what they should be when you get there

The Shooting Method for Boundary-value Problems Consider the following non-linear boundary-value problem: The corresponding function is function [dw] = f6c( x, w ) dw = [w(2); sin(x) - 4*w(2)*w(1) + 2*x*w(1)^2]; end

The Shooting Method When I run the function The Shooting Method for Boundary-value Problems The Shooting Method When I run the function [x6c, u6c] = shooting( -3, -3.1, @f6c, [2, 3], [1.5, 2.5]', ... 0.01, 1e-6, 1e-6, 20 ); I get a solution after four iterations where the approximations of the initial slopes are: –3.326745004558498 –3.323136496135223 –3.323176635129875 –3.323176642445732 These last two slopes are sufficiently close enough and the u6c(1, end) = 2.499999999999991 close enough to 2.5

The Shooting Method We can look at the plot and the result: The Shooting Method for Boundary-value Problems The Shooting Method We can look at the plot and the result: plot( xs, us(1,:) ) us(1,end) ans = 2.499999999999991 length( xs ) 36

The Shooting Method for Boundary-value Problems You might get slightly different values depending on your implementation of the secant method; however, the final result should be reasonably close

The Shooting Method Plotting approximations with the various slopes: The Shooting Method for Boundary-value Problems The Shooting Method Plotting approximations with the various slopes: slopes = [-3 -3.1 -3.326745004558498 -3.323136496135223 ... -3.323176635129875 -3.323176642445732]; for s = slopes [x6s, u6s] = dp45( @f6c, [2, 3], [1.5, s]', 0.01, 1e-6 ); plot( x6s, u6s(1,:) ) u6s(1,end) end s1 = 3 s2 = 3.1 All others...

The Shooting Method for Boundary-value Problems If you plot the relative errors of the approximation of u6s(1,end) as an approximation of ub = 2.5, we observe the fast (i.e., O(hf)) convergence of the secant method s u6s(1,end) Absolute Error –3 2.668638013935938 1.686 × 10–1 –3.1 2.617026509067240 1.170 × 10–1 –3.326745004558498 2.498107476136670 1.893 × 10–3 –3.323136496135223 2.500021288156047 2.129 × 10–5 –3.323176635129875 2.500000003879338 3.879 × 10–9 –3.323176642445732 2.499999999999991 7.105 × 10–15

Hints You will work with various values of s and err(s) The Shooting Method for Boundary-value Problems Hints You will work with various values of s and err(s) Instead of continually recalculating value err(s), just calculate err1 = err_shot( s1 ); err2 = err_shot( s2 ); and when you calculate a new value of s, just use a simpler expression with the variables s1, s2, err1 and err2 and then immediately calculate errs = err( s ); When you update s1 and s2, update err1 and err2

The Shooting Method for Boundary-value Problems Summary We have looked at using the function dp45 to approximate a boundary-value problem The shooting method converts a BVP into an IVP For linear IVPs, we use the ODE and the homogeneous ODE and find a linear combination of the two solutions For non-linear IVPs, we use dp45 and the secant method to guide us to an approximation

The Shooting Method for Boundary-value Problems References [1] Glyn James, Modern Engineering Mathematics, 4th Ed., Prentice Hall, 2007. [2] Glyn James, Advanced Modern Engineering Mathematics, 4th Ed., Prentice Hall, 2011. [3] John H. Mathews and Kurtis D. Fink, Numerical Methods using Matlab, 4th Ed., Prentice Hall, 2004, pp. 529-534. [4] Shooting Method, http://en.wikipedia.org/wiki/Shooting_method.