Ordinary Differential Equations. Outline Announcements: –Homework II: Solutions on web –Homework III: due Wed. by 5, by e-mail Structs Differential Equations.

Slides:



Advertisements
Similar presentations
Lecture 5 Fixed point iteration Download fixedpoint.m From math.unm.edu/~plushnik/375.
Advertisements

Numerical Computation Lecture 4: Root Finding Methods - II United International College.
Intro to modeling April Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.
A MATLAB function is a special type of M-file that runs in its own independent workspace. It receives input data through an input argument list, and returns.
Dynamics of a four-bar linkage
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.
Where to Go Next. Outline Announcements: –Homework IV due Wed. 10/8 by 5, by Extra week for projects Absolutely no exceptions! Answers will be.
Ordinary Differential Equations
Lecture 16 Symbolic Mathematics Symbolic mathematics: algebraezplotcalculus © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
MATLAB Lecture Two (Part II) Thursday/Friday, July 2003.
Total Recall Math, Part 2 Ordinary diff. equations First order ODE, one boundary/initial condition: Second order ODE.
CIS 101: Computer Programming and Problem Solving Lecture 7 Usman Roshan Department of Computer Science NJIT.
Ordinary Differential Equations. Outline Announcements: –Homework II: Solutions on web –Homework III: due Wed. by 5, by Homework II Differential.
Ordinary Differential Equations. Outline Announcements: –Homework II: Solutions on web –Homework III: due Wed. by 5, by Homework II Differential.
Ordinary Differential Equations (ODEs) 1Daniel Baur / Numerical Methods for Chemical Engineers / Implicit ODE Solvers Daniel Baur ETH Zurich, Institut.
Nonlinear Algebraic Systems 1.Iterative solution methods 2.Fixed-point iteration 3.Newton-Raphson method 4.Secant method 5.Matlab tutorial 6.Matlab exercise.
NUMERICAL SOLUTION OF ORDINARY DIFFERENTIAL EQUATIONS
Ordinary Differential Equations (ODEs)
Differential Equations
Ordinary Differential Equations (ODEs) 1Daniel Baur / Numerical Methods for Chemical Engineers / Explicit ODE Solvers Daniel Baur ETH Zurich, Institut.
Numerical Solution of Ordinary Differential Equation
Solving ODEs UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the Creative.
Ordinary Differential Equations (ODEs) 1Daniel Baur / Numerical Methods for Chemical Engineers / Explicit ODE Solvers Daniel Baur ETH Zurich, Institut.
Lecture 24 Introduction to state variable modeling Overall idea Example Simulating system response using MATLAB Related educational modules: –Section 2.6.1,
Numerical Solutions to ODEs Nancy Griffeth January 14, 2014 Funding for this workshop was provided by the program “Computational Modeling and Analysis.
Design of an ODE Solver Environment. System of ODEs Consider the system of ODEs: Typically solved by forward Euler or 4th order Runge-Kutta.
REVIEW 2 Exam History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.
Analytical vs. Numerical Minimization Each experimental data point, l, has an error, ε l, associated with it ‣ Difference between the experimentally measured.
Computational Methods for Design Lecture 4 – Introduction to Sensitivities John A. Burns C enter for O ptimal D esign A nd C ontrol I nterdisciplinary.
Mikael Johansson and Frank Lingelbach Department of Signals, Sensors, and Systems Introduction to Matlab 2E1215, Lecture 2 – Matlab Programming
Modelling & Simulation of Chemical Engineering Systems Department of Chemical Engineering King Saud University 501 هعم : تمثيل الأنظمة الهندسية على الحاسب.
Functions CS 103 March 3, Review A function is a set of code we can execute on command to perform a specific task A function is a set of code we.
Functions CS 103. Review A function is a set of code we can execute on command to perform a specific task When we call a function, we can pass arguments.
Digital Image Processing Lecture10: MATLAB Example – Utility M-functions for Intensity Transformations.
COMP 116: Introduction to Scientific Programming Lecture 11: Functions.
Numerical Methods for Solving ODEs Euler Method. Ordinary Differential Equations  A differential equation is an equation in which includes derivatives.
+ Numerical Integration Techniques A Brief Introduction By Kai Zhao January, 2011.
Hank Childs, University of Oregon Lecture #6 CIS 410/510: Advection (Part 1)
Beginning Programming for Engineers
Introduction to MATLAB Session 4 Simopekka Vänskä, THL 2010.
Solution of Nonlinear Functions
559 Fish 559; Lecture 5 Non-linear Minimization. 559 Introduction Non-linear minimization (or optimization) is the numerical technique that is used by.
6.094 Introduction to programming in MATLAB Danilo Šćepanović IAP 2008 Lecture 3 : Solving Equations and Curve Fitting.
Ordinary Differential Equations (ODEs) 1Michael Sokolov / Numerical Methods for Chemical Engineers / Explicit ODE Solvers Michael Sokolov ETH Zurich, Institut.
Newton’s Method, Root Finding with MATLAB and Excel
Linear Systems What is the Matrix?. Outline Announcements: –Homework III: due Today. by 5, by –Ideas for Friday? Linear Systems Basics Matlab and.
Chapter 10 ordinary differential equations (ODEs) Chapter 11 systems of ODEs (6 th edition)
Introduction to the Runge-Kutta algorithm for approximating derivatives PHYS 361 Spring, 2011.
Recap Cubic Spline Interpolation Multidimensional Interpolation Curve Fitting Linear Regression Polynomial Regression The Polyval Function The Interactive.
More Functions in MATLAB. Functions that operate on other functions A function F() can take another function G() as an argument by using a notation:
Please remember: When you me, do it to Please type “numerical-15” at the beginning of the subject line Do not reply to my gmail,
Part 6 Chapter 21 Adaptive Methods and Stiff Systems PowerPoints organized by Dr. Michael R. Gustafson II, Duke University All images copyright © The McGraw-Hill.
Input Output Garbage In, Garbage Out. Outline Announcements: –Homework III: due Today. by 5, by Discuss on Friday. –Homework IV: on web, due following.
Lecture 6 - Single Variable Problems & Systems of Equations CVEN 302 June 14, 2002.
Recap Functions with No input OR No output Determining The Number of Input and Output Arguments Local Variables Global Variables Creating ToolBox of Functions.
Root Finding UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the Creative.
Higher Computing Science 2016 Prelim Revision. Topics to revise Computational Constructs parameter passing (value and reference, formal and actual) sub-programs/routines,
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
ACSL, POSTECH1 MATLAB 입문 CHAPTER 8 Numerical Calculus and Differential Equations.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 6 - Chapters 22 and 23.
Input Output Garbage In, Garbage Out. Outline Announcements: –HWII solutions on web soon –Homework III: due Wednesday Advanced ASCII Binary Basics Cell-arrays.
Announcements Topics: -sections 6.4 (l’Hopital’s rule), 7.1 (differential equations), and 7.2 (antiderivatives) * Read these sections and study solved.
Introduction to Programming for Mechanical Engineers
SLOPE FIELDS & EULER’S METHOD
Non-linear Minimization
One-layer neural networks Approximation problems
User Defined Functions
ENGG 1801 Engineering Computing
Objective Numerical methods Finite volume.
Derivatives and Gradients
Presentation transcript:

Ordinary Differential Equations

Outline Announcements: –Homework II: Solutions on web –Homework III: due Wed. by 5, by Structs Differential Equations Numerical solution of ODE’s Matlab’s ODE solvers Optimization problems Matlab’s optimization routines

Strings –charcell={‘Greetings’; ‘People of Earth’} –disp(charcell) will output each cell on a new line ‘Greetings’ ‘People of Earth’ –Search lines using strmatch strmatch('Greetings',charcell) Encapsulating data –FFTcell={a, b, dt} myfft could return a cell array in this form Would keep the related data together But, user would have to know what is in each cell Applications of Cell-arrays

Structs Rather than storing data in elements or cells, structs store data in fields Better encapsulation than cell –FFTstrct.a=a; –FFTstrct.b=b; –FFTstrct.dt=dt; Can have arrays of structs –for j=1:n strctarr(j)=StrctFunc(inputs); –end –each element must have same fields

Working with Structs –Lots of commands for working with structs fieldnames(S)--returns a cell array of strings containing names of fields in S isfield(S,’fname’)--checks whether fname is a field of S rmfield(S,’fname’)--removes fname

Differential Equations Ordinary differential equations (ODE’s) arise in almost every field ODE’s describe a function y in terms of its derivatives The goal is to solve for y

Example: Logistic Growth N(t) is the function we want (number of animals)

Numerical Solution to ODEs In general, only simple (linear) ODEs can be solved analytically Most interesting ODEs are nonlinear, must solve numerically The idea is to approximate the derivatives by subtraction

Euler Method

Simplest ODE scheme, but not very good “1st order, explicit, multi-step solver” General multi-step solvers: (weighted mean of f evaluated at lots of t’s)

Runge-Kutta Methods Multi-step solvers--each N is computed from N at several times –can store previous N’s, so only one evaluation of f/iteration Runge-Kutta Methods: multiple evaluations of f/iteration:

ODE Solvers LMS and RK solvers are general algorithms that can work with any ODE Need a way to pass the function f to the solver f N t dN/dt Solver N0 t0 T N 1, N 2,…,N T

Passing Functions One sol’n: force us to call our function “f” A better sol’n: –pass the name of the function to the solver funcname=“myf” –solver uses “feval” command dN=feval(funcname,N,t); –This is Matlab ca. 1998

Passing Functions Now, feval accepts “function handles” creates a handle to myf.m Slightly faster than strings Now, how do we solve the ODE’s?

Matlab’s ODE solvers Matlab has several ODE solvers: –ode23 and ode45 are “standard” RK solvers –ode15s and ode23s are specialized for “stiff” problems –several others, check help ode23 or book

All solvers use the same syntax: t, N0, {options, params …}) odefile is the name of a function that implements f –function f=odefile(t, N, {params}), f is a column vector –t is either [start time, end time] or a vector of times where you want N –N0= initial conditions –options control how solver works (defaults or okay) –params= parameters to be passed to odefile Matlab’s ODE solvers

Parameters To accept parameters, your ode function must be polymorphic –f=odefile(t,x); –f=odefile(t,x,params); –function f=odefile(t,x,params); if(nargin<3) –params=defaults; end f=…

Matlab functions can be polymorphic--the same function can be called with different numbers and types of arguments –Example: plot(y), plot(x,y), plot(x,y,’rp’); In a function, nargin and nargout are the number of inputs provided and outputs requested by the caller. Even more flexibility using varargin and varargout nargin

Example: Lorenz equations Simplified model of convection cells In this case, N is a vector =[x,y,z] and f must return a vector =[x’,y’,z’]

Optimization For a function f(x), we might want to know –at what value of x is f smallest –largest? –equal to some value? All of these are optimization problems Matlab has several functions to perform optimization –Same problem as with ODE: solver needs to work with YOUR functions –Must pass function handle

Optimization Simplest functions are x0);%Finds f(x)==0 starting from x0 [xL, xR]); %Finds minimum in interval [xL,xR] %Finds minimum starting at x0 All of these functions require you to write a function implementing f: –function f=fun(x);%computes f(x)

Optimization Toolbox More optimization techniques, but used in the same way –Some of these functions can make use of gradient information –in higher dimensions, gradient tells you which way to go, can speed up procedure f df/dx = 0

Optimization Toolbox To return gradient information, your function must be polymorphic: –x=fun(x) %return value –[x,dx]=fun(x); %return value and gradient –function [x,dx]=fun(x); if(nargout>1) –dx=… end x=…

Optimization Options Need to tell optimization toolbox that it can use gradient –Use optimset: opts=optimest(‘ParameterName’,’value’); Then pass opts to optimization function Lots of options--read docs! –opts=optimset(‘GradObj’,’on’);%Turns gradient on x0,opts);%pass opts to function

Summary ODE solvers & optimization routines in Matlab are “function functions” –You must write a function returning dx/dt (ODE) f (Optimization) –You pass the name of the function to the solver –Solver calls it repeatedly and returns answer