Numerical solution of ODEs

Similar documents
2D Plotting with Matlab

Homework 1 Solutions

Matlab Section. November 8, 2005

Numerical Methods - Boundary Value Problems for ODEs

LAB 1: MATLAB - Introduction to Programming. Objective:

System Simulation using Matlab

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

Matlab for Review. NDSU Matlab Review pg 1

MAT 275 Laboratory 4 MATLAB solvers for First-Order IVP

We begin exploring Euler s method by looking at direction fields. Consider the direction field below.

MAT 275 Laboratory 4 MATLAB solvers for First-Order IVP

Introduction to MatLab

NUMERICAL METHODS. lor CHEMICAL ENGINEERS. Using Excel', VBA, and MATLAB* VICTOR J. LAW. CRC Press. Taylor & Francis Group

Practical Course Scientific Computing and Visualization

Octave. Tutorial. Daniel Lamprecht. March 26, Graz University of Technology. Slides based on previous work by Ingo Holzmann

Introduction to Computational Neuroscience

The Plan. Initial value problems (ivps) for ordinary differential equations (odes) Review of basic methods You are here: Hamiltonian systems

Simulink Tutorial 1 CPE562

EE 4314 Lab 1 Handout Control Systems Simulation with MATLAB and SIMULINK Spring Lab Information

APPLICATIONS OF FD APPROXIMATIONS FOR SOLVING ORDINARY DIFFERENTIAL EQUATIONS

MTH 452/552 Homework 3

1. Open polymath: 2. Go to Help, Contents F1 or Press F1

Integration by Parts Logarithms and More Riemann Sums!

EGR 140 Lab 6: Functions and Function Files Topics to be covered : Practice :

Ordinary Differential Equations (ode)

MAT 275 Laboratory 4 MATLAB solvers for First-Order IVP

Wed Jan Improved Euler and Runge Kutta. Announcements: Warm-up Exercise:

Solving Linear Systems of ODEs with Matlab

An Introduction to MatLab

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

Matlab homework assignments for modeling dynamical systems

Computer lab for MAN460

Read through A Graphing Checklist for Physics Graduate Students before submitting any plots in this module. See the course website for the link.

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

Ordinary Differential equations

January 18, 2008 Steve Gu. Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB,

EEE161 Applied Electromagnetics Laboratory 1

AMS 27L LAB #8 Winter 2009

Statistical methods. Mean value and standard deviations Standard statistical distributions Linear systems Matrix algebra

Understand the existence and uniqueness theorems and what they tell you about solutions to initial value problems.

Introduction to MATLAB Practical 2

Initial value problems for ordinary differential equations

25 Self-Assessment. 26 Eigenvalue Stability for a Linear ODE. Chapter 7 Eigenvalue Stability

Lecture 7 Symbolic Computations

The Euler Method for the Initial Value Problem

Part 1. The diffusion equation

WILEY. Differential Equations with MATLAB (Third Edition) Brian R. Hunt Ronald L. Lipsman John E. Osborn Jonathan M. Rosenberg

Lecture 17: Ordinary Differential Equation II. First Order (continued)

Lecture 5b: Starting Matlab

Solutions to Homework 3

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

MATLAB crash course 1 / 27. MATLAB crash course. Cesar E. Tamayo Economics - Rutgers. September 27th, /27

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

JMBC Computational Fluid Dynamics I Exercises by A.E.P. Veldman

Example 1 (Characteristic Equation, Eigenvalue, and Eigenvector)

MATH2071: LAB 3: Implicit ODE methods

. var save filename var. y fprintf(fl,'%f %f\n',y) y ..TXT. . fprintf() .TXT. myf = fopen('nam.txt','w'); nam.txt myf.

Math 98 - Introduction to MATLAB Programming. Spring Lecture 3

ODE Homework 1. Due Wed. 19 August 2009; At the beginning of the class

Finite Difference Method

Lecture 8: Calculus and Differential Equations

Lecture 8: Calculus and Differential Equations

Lab 4 Numerical simulation of a crane

Modeling and Solving Constraints. Erin Catto Blizzard Entertainment

1 TIME OF ARRIVAL LOCATION TECHNIQUE

MATLAB Project 2: MATH240, Spring 2013

CHEE 222: PROCESS DYNAMICS AND NUMERICAL METHODS

ENED 1091 HW#3 Due Week of February 22 nd

Polytechnic Institute of NYU MA 2132 Final Practice Answers Fall 2012

I. Numerical Computing

Lecture 4. Programming

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

10.34 Numerical Methods Applied to Chemical Engineering Fall Homework #4: IVP

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

Conformational Analysis of n-butane

Temperature measurement

Riemann Integration. James K. Peterson. February 2, Department of Biological Sciences and Department of Mathematical Sciences Clemson University

1 Introduction to MATLAB

1 Some general theory for 2nd order linear nonhomogeneous

(6.2) -The Shooting Method for Nonlinear Problems

Ordinary Differential Equations. Monday, October 10, 11

Additional Homework Problems

Math 515 Fall, 2008 Homework 2, due Friday, September 26.

Athena Visual Software, Inc. 1

Homework #6 Solutions

ENGR Spring Exam 2

10. Linear Systems of ODEs, Matrix multiplication, superposition principle (parts of sections )

Homework Assignment 4 Root Finding Algorithms The Maximum Velocity of a Car Due: Friday, February 19, 2010 at 12noon

Chemical Engineering 436 Laplace Transforms (1)

HOMEWORK 3: Phase portraits for Mathmatical Models, Analysis and Simulation, Fall 2010 Report due Mon Oct 4, Maximum score 7.0 pts.

Companion. Jeffrey E. Jones

Assignment 6, Math 575A

Lecture 3: Special Matrices

Numerical Methods for Embedded Optimization and Optimal Control. Exercises

Riemann Integration. Outline. James K. Peterson. February 2, Riemann Sums. Riemann Sums In MatLab. Graphing Riemann Sums

2 Getting Started with Numerical Computations in Python

Differential equations and numerical methods / M.E. Mincsovics

2007 Summer College on Plasma Physics

Chemical reaction networks and diffusion

MATLAB BASICS. Instructor: Prof. Shahrouk Ahmadi. TA: Kartik Bulusu

Transcription:

Péter Nagy, Csaba Hős 2015. H-1111, Budapest, Műegyetem rkp. 3. D building. 3 rd floor Tel: 00 36 1 463 16 80 Fax: 00 36 1 463 30 91 www.hds.bme.hu

Table of contents Homework Introduction to Matlab programming Solution of an initial value problem (IVP) Solution of a boundary value problem (BVP)

Homework Homework: The homework and these slides will be available on: http://www.hds.bme.hu/mota/eng/denum/index.html Submission: Only the source code and the plots have to be archived and submitted to pnagy@hds.bme.hu as NC_Name.zip. The subject has to be DENUM NC Name. The deadline is the end of 12 th week. Programming language: Matlab preferred, otherwise personal submission with own laptop is necessary Free alternatives: Octave, Freemat, Scilab

Introduction to Matlab programming MATLAB (matrix laboratory) is a multi-paradigm numerical computing environment Current folder! Menu Command window Workspace Text editor Errors, warnings File explorer

Useful commands 1. Type stg. + Tab key -> autocomplete F1 key over a function -> Help+description+syntax ; at the end of a command -> the output is not written to the command window clc -> Clear command window clear all -> Delete variables close all -> close figures Avoid overwriting predefined functions and variables (F1 or Tab)!!! Predefined variables: pi, i-imaginary unit, exp(1) Euler number function output = name(var1, var2) global var1 var2 -> define global variables, subfunctions can read them [x1, x2, x3] -> generates a row vector [x1; x2; x3] -> generates a column vector A -> the transpose of A (A can be a matrix or a vector)

Useful commands 2 {.+.-.*./} -> calculate {+ - * /} element by element Defining vectors linspace(a, b, n) -> generates linearly spaced vectors between a and b, n is the number of elements a:b generates linearly spaced vectors between a and b, increment is 1 a:deltax:b generates linearly spaced vectors between a and b, increment is deltax v(i) -> the ith element of the vector A(i,j) -> the element of a matrix in the row i and column j A(i,:) -> the i th row of a matrix ; A(:,j) -> the j th column of a matrix Loops for i=1:num_steps end %code %comment while (statement) end %code %comment

Useful commands 3 Define functions f(x,y) = Expression can be defined in Matlab f=@(x,y) Expression; -> for simple expression (eg. ODES) or function output = f (x,y) output=expression; -> for longer, more complex calculation (eg. solver) end Important functions [t, y]=ode45(@(t,y) f(y,t), t 0, x 0 ) -> solve ODE (f(y,t)); initial time: t 0 ;initial condition x 0 fminsearch=(@(y) f(y, var1, var2), y 0 ) -> minimize f(y), the initial guess is y 0 Measure computation time (t) tic %code toc (or t=toc)

Useful commands 4 Visualization figure(i) -> generates an empty figure, (i is an integer) subplot(n, m, i) -> generates sub figures, n: number of rows, m: num. of columns, i: is the active subplot plot(x,y) -> plot points; x and y are vectors, further possibilities-> F1 in the case of multiple plots plot(x 1,y 1, x 2,y 2, x 3,y 3 ), where x i,y i are vectors title('title') -> generates title legend('title') -> generates title xlabel('label of x axis'), ylabel('label of y axis'), xlim([xmin xmax]), ylim([ymin ymax]) saveas(figure(i), 'name.png') -> save figure(i) as name.png

Solution of an IVP

Transcript the differential equation The ODE is given 1. If the ODE is higher order transform to first order ODE System Example: t (0) 0 y= f y, ; y y x t c x t s x t g x, t ; x 0 =x ; x 0 =x 0 0 In matrix form: x : y ; x : y x : y ; 1 2 2,, y t c y t sy t g x t 2 2 1 y t cy t sy t g x t y= y ; 2 2 1 T 1 y2 y1= x y2 0 1 0 x0 y= t (0) 0 s c y +, ; g y2, t f y y y x 0

Example In the case of Van der Pool oscillator 2 2 2 x 1 x x x 0; x 0 =x ; x 0 =x y 1 y y y 0 2 1 2 1 y 1 y y y y 2 1 2 1 y 1 2 0 0 Implemented as VdP_rhs(t,y) in ExpImplEu_VanDerPol_new.m

Explicit Euler method 2. Select a solver Explicit Euler method Implemented as y y dt f y n 1 n n n, t

Implicit Euler method Implicit Euler method y y dt f y Implemented as n1 n n1 n1 Try to minimize the expression n n1 n1 n1, t y dt f y, t y 0 r y = y dt f y, t y 0 n1 n n1 n1 n1

Break

Adaptive timestep Problem: Large timestep -> accuracy, stability problems Small timestep -> computationally expensive (=slow) Idea: 1. Predict the local error -> 2. hold between given limits 1. Prediction of the local error Calculate one step in two different ways with different accuracy (but with the same scheme!) The accuracy can be changed: the order of the scheme is changed (ode45) Solve the problem with different stepsize. First, in one step with dt, then in two steps with dt/2

Adaptive timestep The error: 1 n1 2 n1 Hold the error between limits y y the less accurate result the more accurate result 2 1 e = y n1 y n1 min, max If the estimated error is too large Else max max do not store the results decrease the timestep dt r dt r<1 new old store the results If the est. error is too small min increase the timestep

Adaptive timestep Implemented as:

Accuracy of solvers The problem: x t x t 3sin 2t ; x 0 = 2; x 0 = 1 sin y t y t 3 2t 2 1 y1= x y2 y 0 2 1 Analytical solution: sin cos sin x t t 2 t 2t

Accuracy of solvers

Accuracy of solvers

Boundary value problem x t y t v g x t 0 0 y t 0 0 y x 1 0 x t vt 0 y t x / v 0 y t 0 1?

BVP-Shooting method y t g y t 0 0 y t 0 Solve Implemented as: / D : y t x v D 0 1

BVP-Finite differences y t g y t 0 0 y t 1 / v 0 y 2y y y t 2 t yi 1 2yi yi 1 g 2 t i1 i i1 2 yi 1 2yi yi 1 t g 2 1 y2 1 1 2 y 3 1 2 tg y 1 2 1 n2 1 1 2 y n1 1

BVP-Finite differences

Thank you for your attention!