2D1240 Numerical Methods II / André Jaun, NADA, KTH NADA

Similar documents
2D1240 Numerical Methods II / André Jaun, NADA, KTH NADA

(6.2) -The Shooting Method for Nonlinear Problems

Numerical Methods - Boundary Value Problems for ODEs

APPLICATIONS OF FD APPROXIMATIONS FOR SOLVING ORDINARY DIFFERENTIAL EQUATIONS

Chap. 20: Initial-Value Problems

SYSTEMS OF ODES. mg sin ( (x)) dx 2 =

MecE 390 Final examination, Winter 2014

Computation Fluid Dynamics

Optimization and Calculus

Initial Value Problems

Practice Problems for Final Exam

PowerPoints organized by Dr. Michael R. Gustafson II, Duke University

Ordinary Differential equations

Multiplication of Polynomials

Computational Methods CMSC/AMSC/MAPL 460. Solving nonlinear equations and zero finding. Finding zeroes of functions

Numerical Solutions of Boundary Value Problems

Ordinary Differential Equations (ode)

Exercises, module A (ODEs, numerical integration etc)

Differential Equations FMNN10 Graded Project #1 c G Söderlind 2017

Numerical Analysis II. Problem Sheet 12

PowerPoints organized by Dr. Michael R. Gustafson II, Duke University

Ordinary Differential Equations (ODEs)

An Overly Simplified and Brief Review of Differential Equation Solution Methods. 1. Some Common Exact Solution Methods for Differential Equations

Chapter 4: Numerical Methods for Common Mathematical Problems

The Fundamental Theorem of Calculus

Numerical Methods for Embedded Optimization and Optimal Control. Exercises

Logistic Map, Euler & Runge-Kutta Method and Lotka-Volterra Equations

Graded Project #1. Part 1. Explicit Runge Kutta methods. Goals Differential Equations FMN130 Gustaf Söderlind and Carmen Arévalo

Coupled differential equations

Exam 2 Study Guide: MATH 2080: Summer I 2016

Chapter 11 ORDINARY DIFFERENTIAL EQUATIONS

Homework 2 - Solutions MA/CS 375, Fall 2005

BOUNDARY VALUE PROBLEMS

Modeling & Simulation 2018 Lecture 12. Simulations

Finite-Elements Method 2

1. Consider the initial value problem: find y(t) such that. y = y 2 t, y(0) = 1.

Chapter Two: Numerical Methods for Elliptic PDEs. 1 Finite Difference Methods for Elliptic PDEs

The family of Runge Kutta methods with two intermediate evaluations is defined by

Numerical Methods. Root Finding

MAT 275 Laboratory 4 MATLAB solvers for First-Order IVP

Outline. Additional Nonlinear Systems. Abstract. Finding Equilibrium Points Numerically. Newton s Method

PHYS 410/555 Computational Physics Solution of Non Linear Equations (a.k.a. Root Finding) (Reference Numerical Recipes, 9.0, 9.1, 9.

Butcher tableau Can summarize an s + 1 stage Runge Kutta method using a triangular grid of coefficients

ODE Runge-Kutta methods

The Shooting Method for Boundary Value Problems

Solutions to Section 1.1

Fourth Order RK-Method

Ordinary Differential Equations: Initial Value problems (IVP)

MATH 2053 Calculus I Review for the Final Exam

MAT 275 Laboratory 4 MATLAB solvers for First-Order IVP

Numerical Methods for the Solution of Differential Equations

CS520: numerical ODEs (Ch.2)

Lesson 9: Predator-Prey and ode45

Getting Started With The Predator - Prey Model: Nullclines

Problem set 7 Math 207A, Fall 2011 Solutions

MAT 275 Laboratory 4 MATLAB solvers for First-Order IVP

INTRODUCTION TO NUMERICAL ANALYSIS

Computers, Lies and the Fishing Season

Algebra II Through Competitions Chapter 7 Function Composition and Operations

Consider the following example of a linear system:

Ordinary differential equations - Initial value problems

Numerical methods. Examples with solution

AIMS Exercise Set # 1

DRAFT - Math 101 Lecture Note - Dr. Said Algarni

The Derivative. Appendix B. B.1 The Derivative of f. Mappings from IR to IR

Initial value problems for ordinary differential equations

Solving Nonlinear Equations

Motivation: We have already seen an example of a system of nonlinear equations when we studied Gaussian integration (p.8 of integration notes)

Mon Jan Improved acceleration models: linear and quadratic drag forces. Announcements: Warm-up Exercise:

3.2 A2 - Just Like Derivatives but Backwards

Materials Genome Assessment

MATH 3795 Lecture 13. Numerical Solution of Nonlinear Equations in R N.

Basic Theory of Differential Equations

Solutions to Homework # 1 Math 381, Rice University, Fall (x y) y 2 = 0. Part (b). We make a convenient change of variables:

Math 551 Homework Assignment 3 Page 1 of 6

The Corrected Trial Solution in the Method of Undetermined Coefficients

Module Two: Differential Calculus(continued) synopsis of results and problems (student copy)

An Introduction to Numerical Methods for Differential Equations. Janet Peterson

Astronomy 8824: Numerical Methods Notes 2 Ordinary Differential Equations

Scientific Computing with Case Studies SIAM Press, Lecture Notes for Unit V Solution of

Lecture 7. Root finding I. 1 Introduction. 2 Graphical solution

Optimal Control - Homework Exercise 3

CLASS NOTES Models, Algorithms and Data: Introduction to computing 2018

LECTURE NOTES ELEMENTARY NUMERICAL METHODS. Eusebius Doedel

. For each initial condition y(0) = y 0, there exists a. unique solution. In fact, given any point (x, y), there is a unique curve through this point,

2D1240 Numerical Methods II / André Jaun, NADA, KTH NADA

SHOOTING METHOD IN SOLVING BOUNDARY VALUE PROBLEM

Lecture 2: Review of Prerequisites. Table of contents

Elementary ODE Review

Physics 110 Homework Solutions Week #6 - Wednesday

Solutions to Exam 2, Math 10560

Numerical Methods for ODEs. Lectures for PSU Summer Programs Xiantao Li

1. Method 1: bisection. The bisection methods starts from two points a 0 and b 0 such that

Research Computing with Python, Lecture 7, Numerical Integration and Solving Ordinary Differential Equations

Review Higher Order methods Multistep methods Summary HIGHER ORDER METHODS. P.V. Johnson. School of Mathematics. Semester

Chapter 8. Exploring Polynomial Functions. Jennifer Huss

y 2y = 4 x, Name Form Solution method

Introductory Numerical Analysis

Math Numerical Analysis Mid-Term Test Solutions

Math 2a Prac Lectures on Differential Equations

Transcription:

ND 2D24 Numerical Methods II / ndré Jaun, ND, KTH 2. INITIL- / OUNDRY VLUE PROLEMS 2.. Remember: what we saw during the last lesson Euler and Runge-Kutta methods for solving ODEs Predator-prey model using a system of ODEs nharmonic pendulum writing 2 a order ODE as a system with two ODEs nd 2..2 Overview: what you will learn today oundary value problem Solution by shooting and finite differences 5 theory questions for the exam

2.2 Initial- / oundary value problems (NM 8.7, H.) Take Newton s second law of motion for example! ψ! ψ x v v, x = f(t; x; x ) = This second order problem is specified with 2 additional constraints. Initial value problems satisfy 2 initial conditions (I) at the beginning of the interval m F x(t ) = x ; v(t ) = v Knowing the initial position and velocity of a bullet, where is it going to land? oundary value problems satisfy 2 boundary conditions () at the boundaries = x a ; x(b) = x b x(a) What is the trajectory of a bullet shot a from to b? oundary conditions can be specified as the x(a) value (Dirichlet), the derivative (a) (Neuman) or a linear combination of the two x(a) + ffx (a) = fi (Robin). x

t=[ ]; v=2.5; options=odeset('events','on','outputsel',[2],'refine',5) >> a=pi/6; X=[. v*cos(a) v*sin(a)]; [T,Y]=ode23(shoot,t,X,options); >> a=pi/3; X=[. v*cos(a) v*sin(a)]; [T2,Y2]=ode23(shoot,t,X,options); >> x=:.:.5; plot(x,exp(x.^2), Y(:,),Y(:,2),'--',Y2(:,),Y2(:,2),':') >> 2.3 Shooting method for boundary value problems (NM 8.7., H.3) The method solves initial value problems, adjusting the I to approach the. Shoot from a with a guess velocity; if the bullet falls short, increase the velocity, etc Example determine the canon angle to shoot from the hill (; ) to the target (; =e). varargout = shoot(t,x,flag); function.4 Shooting from the top of a Gaussian hill flag switch '', case.2 varargout } = dydt(t,x); 'events', [varargout :3}]= events(t,x); case error(['unknown flag.']); otherwise, end f=dydt(t,x) function X(4); ; -9.8]; f=[x(3); f=(vx,vy,ax,ay) [value,isterminal,direction]=events(t,x) function vertical coordinate x(2).8.6.4.2 shapemountain=exp(-x()^2); ground elevation = X(2)-shapeMountain; value = ; isterminal present height stop if ground.5.5 horizontal coordinate x() direction = -; going down Here events(t,x) is used to stop the integration when the bullet hits the ground; experimentally, the canon angle is found to be somewhere ff 2 [ß=6; ß=3].

b=pi/3; tol=pi/8; t=[ ]; v=2.5; xtarget=; a=pi/6; options=odeset('events','on','outputsel',[2],'refine',5). v*cos(a) v*sin(a)];[t,y]=ode23(shoot,t,x,options);fa=y(end,)-xtarget; X=[. v*cos(b) v*sin(b)];[t,y]=ode23(shoot,t,x,options);fb=y(end,)-xtarget; X=[ abs(b-a)>tol while x=b-fb*(b-a)/(fb-fa); The solution is computed by solving a non-linear equation f(ff) = x end (ff) x b = : the secant method is most effective when f (ff) is not known explicitly. In Matlab use the same driver shoot() to search with the secant method: fa=fb; b=x; fb=fx; a=b; x b] sol=8/pi*[a.4 Shooting from the top of a Gaussian hill X=[. v*cos(x) v*sin(x)];[t,y]=ode23(shoot,t,x,options);fx=y(end,)-xtarget; end.2 x b a --------------------------- 4.748 4.748 6. 46.476 46.476 4.748 48.2975 48.2975 46.476 47.9854 47.9854 48.2975 vertical coordinate x(2).8.6.4.2 ==> alpha = 48. +/-.3 degree.5.5 horizontal coordinate x() Linear boundary value problems can be solved with a system using only two trials.

i+ 2y + i i y p y i+ y y i i x a 2 + h ha p xi ) ( e i d i y i + ( + p xi ) z } i f b i 2.4 Finite differences for boundary value problems (NM 8.7.2, H.4) The method divides the interval where the solution is sought into equidistant pieces using finite difference (FD) to approximate derivatives with unknowns y i = y(x i ) x i = x a + i h; h = (x b x a )=N i ß y i+ y i y ; y i ß y i+ 2y i + y i h 2 2h here for example with a O(h precision ). Linear example: solve the boundary value problem in the interval 2 2 [; 4] x y + a p xy (6 y)x = ; y() = ;y(4) = for parameter values a 2 f 3; 2; ; ; ; 2g. Discretize using a uniform mesh x i = x a + i h, x a =, x b = 4, h = 4=N where N is the number of intervals. Insert the FD approximation and evaluate for every mesh point x i inside 2h This yields a tridiagonal linear y (E + D + F)y = b system (6 y i )x i = 8i = 2 :::;N i (2 h 2 x i ) z } y i+ = 6h 2 x i z } y ha 8i 2 z } 2

y 2 y n y n y y 2 y n y n y y(a) 2 b oundary conditions are usually imposed by replacing the corresponding equation ::: 2 d 2 f 2 ::: e e 3 d 3 f 3 :::........ y 3. = b 3. ::: e n d n f n ::: n b y(b) and substituting the columns to keep the matrix symmetric if it was in the beginning ::: d 2 f 2 ::: y 3. e 3 d 3 f 3 :::........ = y(a) 2 e 2 y(a) b b 3. ::: e n d n ::: n f n y(b) b y(b) The system is can be solved directly using tridia or solvers for sparse systems.

plot(x,y), subplot(3,2,k); ylabel(l) l=sprintf('a=i',a), In Matlab, this yields X=[; 4]; Y=[; -]; k=:6 for a=k-4; n=; h=diff(x)/(n-); x=linspace(x(),x(2),n)'; e=-.5*h*a*sqrt(x); boundaries parameter a n- intervals assemble tridiagonal d=-(2-h^2*x); matrix f=+.5*h*a*sqrt(x); d [; f(:n-)]],-:,n,n); =spdiags([[e(2:n);] assemble RHS b=6*h^2*x; (,2)=; b()=y(); (,)=.; (n,n-)=; b(n)=y(2); (n,n)=.; y= b; solve a= 3 a= a= 2 2 4 3 2 y +ay x /2 (6 y)x=, y()=, y(4)= 2 4 8 6 4 2 2 2 4 a= 2 a= a=2 2 2 4 2 5 2 4 2 4 end Peer Teaching (2 minutes to think, explain to your neighbour and vote) omputational cost. Examine the number of operations required to solve a linear boundary value problem in dimension. Which method is more efficient? ψ shooting " about equal # cannot say! finite differences

i+ 2y i + y i y 2 + cy 2 i (6 y i)x i = 8i = 2 :::;N h ( G(yi ) = (2 h 2 x i )y i + ch 2 y 2 i Non-linear example: solve the boundary value problem in the interval x 2 [; 4] + cy 2 (6 y)x = with y() = ;y(4) = ; for c = : y Discretize using finite differences on a uniform mesh b i = 6h 2 x i This non-linear system of the form F(y) = is solved after inserting the boundary conditions using the Newton method y new = y old + ffiy, withjffiy = f(y old ). The Jacobian matrix J i;j = F i =y j is tridiagonal y i + G(y i ) + y i+ b i = with (y ) ::: G G (y 2 ) :::..... J = ::: G (y n ) ::: G (y n ) with G (y i ) = (2 h 2 x i ) + 2ch 2 y i. What should we take for the initial guess?

randolinj, y"+c*y^2=(6-y)x; y()=;y(4)=- bandmatrix, non-linear system with Newton's method clf clear, xend= 4; x=[ xend]; x=; yend=-; y=[ ]; plot(x,y); hold on y=; + cy^2 =(6-y)x, y()=, y(4)=- ') title('y" ntot=4; h=xend/ntot; Solve linear problem with c= for an initial guess c= one=ones(n-,); b=6*h^2*x; dia=-(2-h^2*x); b(n)=b(n)-yend; b()=b()-y; y=tridia(dia,one,one,b); x; xend]; Y=[y; y; yend]; plot(x,y,'--') X=[; Method: gradually increase the non-linearity With strongly non-linear equations, first switch-off the non-linear term and calculate a linear solution for the inital guess. Then gradually switch-on the nonlinearity, using increasingly non-linear solutions to start the Newton iterations. In Matlab this can be implemented as n=ntot-; x=h*(:n)'; [ymax,ix]=max(y); text(x(ix),ymax,'c='), drawnow

ymax [ymax,ix]=max(y); num2str(c)]), drawnow text(x(ix),ymax,['c=' end plot(x,y,'r') Gradually increase c using Newton's method with previous solutions as initial guess 4 y" + cy 2 =(6 y)x, y()=, y(4)= cvec=[.25.5.]; nr=:3 for err=; c=cvec(nr), experimentally iter=; 3 2 c=. c=.25 c=.5 err>e-4 & iter<5 while Gprim=dia+2*c*h^2*y; G=dia.*y+c*h^2*y.^2; y(:n-)]+g+[y(2:n);yend]-6*h^2*x; F=[y; J dy=-f(y) dy=-tridia(gprim,one,one,f); err=norm(dy,inf)/norm(y,inf) iter=iter+; y=y+dy; end iter==5, disp('no convergence'),break,end if 2 c= 3 2 3 4 Y=[y; y; yend]; plot(x,y,':') The non-linearity is very strong as can be seen from the plot.