MATLAB EXAMPLES Initial-value problems

Slides:



Advertisements
Similar presentations
Prof. Muhammad Saeed ( Ordinary Differential Equations )
Advertisements

Chapter 6 Differential Equations
Dr. Guy Tel-Zur Computational Physics Differential Equations Autumn Colors, by Bobby Mikul, Mikul Autumn Colors,
Differential Equations Math Review with Matlab: Finding Solutions to Differential Equations S. Awad, Ph.D. M. Corless, M.S.E.E. D. Cinpinski E.C.E. Department.
Numeriska beräkningar i Naturvetenskap och Teknik 1. Numerical differentiation and quadrature Discrete differentiation and integration Trapezoidal and.
Mechanical Engineering Majors Authors: Autar Kaw, Charlie Barker
5/19/ Runge 4 th Order Method Mechanical Engineering Majors Authors: Autar Kaw, Charlie Barker
CSE245: Computer-Aided Circuit Simulation and Verification Lecture Note 5 Numerical Integration Spring 2010 Prof. Chung-Kuan Cheng 1.
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 32 Ordinary Differential Equations.
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 31 Ordinary Differential Equations.
Multistep methods previous methods use information at xi to predict yi+1 multistep methods use information from xi-1, xi-2, etc. leads to better results.
Ordinary Differential Equations (ODEs) 1Daniel Baur / Numerical Methods for Chemical Engineers / Implicit ODE Solvers Daniel Baur ETH Zurich, Institut.
Ordinary Differential Equations (ODEs)
Ordinary Differential Equations (ODEs) 1Daniel Baur / Numerical Methods for Chemical Engineers / Explicit ODE Solvers Daniel Baur ETH Zurich, Institut.
MATH 685/ CSI 700/ OR 682 Lecture Notes Lecture 10. Ordinary differential equations. Initial value problems.
P ROJECT : N UMERICAL S OLUTIONS TO O RDINARY D IFFERENTIAL E QUATIONS IN H ARDWARE Joseph Schneider EE 800 March 30, 2010.
Fin500J Topic 7Fall 2010 Olin Business School 1 Fin500J Mathematical Foundations in Finance Topic 7: Numerical Methods for Solving Ordinary Differential.
1 Chapter 6 Numerical Methods for Ordinary Differential Equations.
Ordinary Differential Equations (ODEs) 1Daniel Baur / Numerical Methods for Chemical Engineers / Explicit ODE Solvers Daniel Baur ETH Zurich, Institut.
-S.SIVARAJA Dept of MATHEMATICS.  N-NUMERICAL  M-METHODS EASY TO LEARN & EASY TO SCORE.
Numerical Solutions to ODEs Nancy Griffeth January 14, 2014 Funding for this workshop was provided by the program “Computational Modeling and Analysis.
9/22/ Runge 2 nd Order Method Major: All Engineering Majors Authors: Autar Kaw, Charlie Barker
1 LES of Turbulent Flows: Lecture 14 (ME EN ) Prof. Rob Stoll Department of Mechanical Engineering University of Utah Fall 2014.
Computational Method in Chemical Engineering (TKK-2109)
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
10/20/ Runge 2 nd Order Method Chemical Engineering Majors Authors: Autar Kaw, Charlie Barker
Modelling & Simulation of Chemical Engineering Systems Department of Chemical Engineering King Saud University 501 هعم : تمثيل الأنظمة الهندسية على الحاسب.
Integration of 3-body encounter. Figure taken from
5/30/ Runge 4 th Order Method Chemical Engineering Majors Authors: Autar Kaw, Charlie Barker
Separation of Variables Solving First Order Differential Equations.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. ~ Ordinary Differential Equations ~ Stiffness and Multistep.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. by Lale Yurttas, Texas A&M University Chapter 261 Stiffness.
11/17/ Shooting Method Major: All Engineering Majors Authors: Autar Kaw, Charlie Barker
Beginning Programming for Engineers
Mathematical Applications using MATLAB (Cont….)
Scientific Computing Multi-Step and Predictor-Corrector Methods.
Ordinary Differential Equations (ODEs) 1Michael Sokolov / Numerical Methods for Chemical Engineers / Explicit ODE Solvers Michael Sokolov ETH Zurich, Institut.
Chapter 10 ordinary differential equations (ODEs) Chapter 11 systems of ODEs (6 th edition)
Recap Cubic Spline Interpolation Multidimensional Interpolation Curve Fitting Linear Regression Polynomial Regression The Polyval Function The Interactive.
ME451 Kinematics and Dynamics of Machine Systems Numerical Integration. Stiffness: Implicit Methods. October 30, 2013 Radu Serban University of Wisconsin-Madison.
1/16/ Runge 4 th Order Method Civil Engineering Majors Authors: Autar Kaw, Charlie Barker
1/19/ Runge 4 th Order Method Major: All Engineering Majors Authors: Autar Kaw, Charlie Barker
2/28/ Runge 4 th Order Method Computer Engineering Majors Authors: Autar Kaw, Charlie Barker
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 6 - Chapters 22 and 23.
Solving Ordinary Differential Equations
Numerical Methods by Dr. Laila Fouad.
Civil Engineering Majors Authors: Autar Kaw, Charlie Barker
CSE245: Computer-Aided Circuit Simulation and Verification
Class Notes 18: Numerical Methods (1/2)
Class Notes 19: Numerical Methods (2/2)
Ch 8.6: Systems of First Order Equations
ME 123 Computer Applications I Lecture 24: Character Strings 4/18/03
Civil Engineering Majors Authors: Autar Kaw, Charlie Barker
Chapter 26.
Industrial Engineering Majors Authors: Autar Kaw, Charlie Barker
CSE245: Computer-Aided Circuit Simulation and Verification
ECE 576 POWER SYSTEM DYNAMICS AND STABILITY
Numerical Solutions of Ordinary Differential Equations
Numerical Analysis Lecture 38.
MATH 175: NUMERICAL ANALYSIS II
ECE 576 POWER SYSTEM DYNAMICS AND STABILITY
Electrical Engineering Majors Authors: Autar Kaw, Charlie Barker
Numerical Computation and Optimization
6th Lecture : Numerical Methods
Differential equations
ME 123 Computer Applications I Lecture 25: MATLAB Overview 4/28/03
Chemical Engineering Majors Authors: Autar Kaw, Charlie Barker
MATH 2140 Numerical Methods
CISE301: Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture KFUPM Read , 26-2, 27-1 CISE301_Topic8L7 KFUPM.
Presentation transcript:

MATLAB EXAMPLES Initial-value problems 58:111 Numerical Calculations MATLAB EXAMPLES Initial-value problems Department of Mechanical and Industrial Engineering

Some useful functions ode23 An explicit one-step Runge-Kutta low order(2nd-3rd)solver ode23s An implicit one-step modified Rosenbrock solver of order two ode23t An implicit one-step trapezoidal rule using a free interpolate ode23tb An implicit trapezoidal rule followed by a backward differentiation rule of order two ode45 An explicit one-step Runge Kutta medium-order (4th-5th) solver ode113 A multistep Adams-Bashforth-Moulton PECE solver of varying order (1st –13th) ode15s An implicit, multistep numerical differentiation solver of varying order (1st-5th)

IVP The initial value problems for 1st order differential equation are defined by the following standard form: Example:   The exact solution is: In the following slides, we will try to solve this problem by Euler and Runge-Kutta methods in MATLAB. The ODE function was defined as M-file (ex1_odefun.m): % IVP function for EX1 function xdot=ex1_odefun(t,x) xdot=x+1;

IVP –Euler method Run this M-file: >> ivp_euler_ex1 Use Euler method to solve the IVP example, step size sets to 0.01. Write the M-file as follows (ivp-euler.ex1.m): % IVP solution - Euler method % example 1: x'=x+1, x(0)=0, solve x(1) % the range of t [a,b] a=0.0; b=1.0; % the initial value of x x=0.0; %the number of steps n=100; %set the matrix x0=zeros(n,1); % set the step size h=(b-a)/100; %set the initial value of t t=a; for k=1:n % Record the values of x in each step x=x+h*ex1_odefun(t,x); x0(k)=x; t=t+h; end %the final result of x x0(100) Run this M-file: >> ivp_euler_ex1 ans = 1.7048

IVP –Runge-Kutta method To use Runge-Kutta method, here we only try ode23 and ode45 (step size =0.1): >> tspan=linspace(0,1,11); >> x0=[0;0]; >> [t,x]=ode23(@ex1_odefun,tspan,x0); >> x(11) ans = 1.7182 >> [t,x]=ode45(@ex1_odefun,tspan,x0); 1.7183 The results show the higher order solver ode45 got more accurate result than ode23 and Euler method.

IVP - Plot To show the accuracy of different methods, we need plot the solution together, the following M-file is for plotting the results of exact, Euler and 4th Runge-Kutta methods (ivp-plot_ex1.m): % IVP solution - plot % example 1 x'=x+1 % the range of t [a,b] a=0.0; b=1.0; % the initial value of x x=0.0; %the number of steps n=10; %set the matrix x1=zeros(n,1); %the step size h=(b-a)/10; %set the initial value of t t=a; %Euler method - Iterations for k=1:n+1 % Record the values of x in each step x1(k)=x; x=x+h*ex1_odefun(t,x); t=t+h; end %plot the results t=linspace(0,1,11); %Runge-Kutta method rx0=[0;0]; [t,x2]=ode45(@ex1_odefun,t,rx0); %exact solution x0=exp(t)-1; plot(t,x0,t,x1,'.',t,x2,'o') xlabel('t') ylabel('x')

IVP - Plot The following figures show the results by different step size h. The solid line is the exact solution, the solid dots represent the result of Euler method, the circles represents the results of 4th order Runge-Kutta method. h = 0.1 h = 0.01

IVP-Summary Compare the results of different methods (all keep 4 digits after the radix point) in the following table (x(1)): Method Solution Exact 1.7183 Euler (h = 0.1) 1.5937 4th Runge-Kutta (h = 0.1) Euler (h = 0.01) 1.7084 4th Runge-Kutta (h = 0.01)