Workpackage 5 - Ordinary Differential Equations

Similar documents
ChE 400: Applied Chemical Engineering Calculations Tutorial 6: Numerical Solution of ODE Using Excel and Matlab

Application 7.6A The Runge-Kutta Method for 2-Dimensional Systems

MAT 275 Laboratory 3 Numerical Solutions by Euler and Improved Euler Methods (scalar equations)

MATH2071: LAB 2: Explicit ODE methods

MAT 275 Laboratory 3 Numerical Solutions by Euler and Improved Euler Methods (scalar equations)

Modelling and Simulation for Engineers

LAB #8 Numerical Methods

Fall 2015 Math 337. Basic MatLab

Thursday 1/8 1 * syllabus, Introduction * preview reading assgt., chapter 1 (modeling) * HW review chapters 1, 2, & 3

dy = dx y dx Project 1 Consider the following differential equations: I. xy II. III.

4 Visualization and. Approximation

=.1( sin(2πx/24) y) y(0) = 70.

Mass-Spring Systems. Last Time?

Euler s Methods (a family of Runge- Ku9a methods)

over The idea is to construct an algorithm to solve the IVP ODE (9.1)

NUMERICAL METHODS, NM (4776) AS

Solution for Euler Equations Lagrangian and Eulerian Descriptions

Module1: Numerical Solution of Ordinary Differential Equations. Lecture 6. Higher order Runge Kutta Methods

Tutorial: Getting Started with the LabVIEW Simulation Module

Excel Scientific and Engineering Cookbook

Working Environment : Python #1

Mars Pinpoint Landing Trajectory Optimization Using Sequential Multiresolution Technique

Mid-Year Report. Discontinuous Galerkin Euler Equation Solver. Friday, December 14, Andrey Andreyev. Advisor: Dr.

Differential Equations (92.236) Listing of Matlab Lab Exercises

Implicit Function Explorations

Flow and Heat Transfer in a Mixing Elbow

over The idea is to construct an algorithm to solve the IVP ODE (8.1)

Columbus State Community College Mathematics Department Public Syllabus. Course and Number: MATH 1172 Engineering Mathematics A

CPIB SUMMER SCHOOL 2011: INTRODUCTION TO BIOLOGICAL MODELLING

Post Processing, Visualization, and Sample Output

A First Course on Kinetics and Reaction Engineering Example S4.5

Module 4: Fluid Dynamics Lecture 9: Lagrangian and Eulerian approaches; Euler's acceleration formula. Fluid Dynamics: description of fluid-motion

Matlab Handout Nancy Chen Math 19 Fall 2004

MATLAB Programming for Numerical Computation Dr. Niket Kaisare Department Of Chemical Engineering Indian Institute of Technology, Madras

Physics Tutorial 2: Numerical Integration Methods

Introduction to MATLAB

MEI STRUCTURED MATHEMATICS. MEI conference University of Hertfordshire June C3 COURSEWORK

Ordinary Differential Equations

Simulation in Computer Graphics. Particles. Matthias Teschner. Computer Science Department University of Freiburg

ODE IVP. An Ordinary Differential Equation (ODE) is an equation that contains a function having one independent variable:

Getting Started in Matlab

Chapter 3 Limits and Derivative Concepts

SIMULINK Tutorial. Select File-New-Model from the menu bar of this window. The following window should now appear.

Final Report. Discontinuous Galerkin Compressible Euler Equation Solver. May 14, Andrey Andreyev. Adviser: Dr. James Baeder

EES Program Overview

Experiment 8 SIMULINK

METU Mechanical Engineering Department ME 582 Finite Element Analysis in Thermofluids Spring 2018 (Dr. C. Sert) Handout 12 COMSOL 1 Tutorial 3

Non-Newtonian Transitional Flow in an Eccentric Annulus

Introduction to Scientific Computing Lecture 8

ADDITIONAL MATHEMATICS FORM 5 SBA

Math 5BI: Problem Set 2 The Chain Rule

MA 243 Calculus III Fall Assignment 1. Reading assignments are found in James Stewart s Calculus (Early Transcendentals)

Ordinary differential equations solving methods

Estimation of Model Parameters Using Limited Data for the Simulation of Electric Power Systems

Module 2: Single Step Methods Lecture 4: The Euler Method. The Lecture Contains: The Euler Method. Euler's Method (Analytical Interpretations)

First Steps - Ball Valve Design

Mathematics 96 (3581) CA (Class Addendum) 2: Associativity Mt. San Jacinto College Menifee Valley Campus Spring 2013

A Simplified Vehicle and Driver Model for Vehicle Systems Development

Approximating Square Roots

Lab #5 Ocean Acoustic Environment

Solution for Euler Equations Lagrangian and Eulerian Descriptions

Exam 2 Preparation Math 2080 (Spring 2011) Exam 2: Thursday, May 12.

FMI WORKSHOP. INCOSE International Workshop, Los Angeles, CA, Contents. Introduction

HW #7 Solution Due Thursday, November 14, 2002

Chemical Reaction Engineering - Part 4 - Integration Richard K. Herz,

USING SPREADSHEETS AND DERIVE TO TEACH DIFFERENTIAL EQUATIONS

Introduction to Simulink

Modeling and Prototypes

SYNOPSIS This case study looks at the design of a small program to calculate escape velocity from the surface of a moon or planet.

Chill Out: How Hot Objects Cool

LAB 2: Linear Equations and Matrix Algebra. Preliminaries

Math Modeling in Java: An S-I Compartment Model

Double Pendulum. Freddie Witherden. February 10, 2009

Isn t it Saturday? IMO Trainning Camp NUK, 2004_06_19 2

FEMLAB Exercise 1 for ChE366

Application 2.4 Implementing Euler's Method

Catholic Regional College Sydenham

Homework Set #2-3, Math 475B

The Space Propulsion Sizing Program

UNIT I READING: GRAPHICAL METHODS

MAT 275 Laboratory 1 Introduction to MATLAB

Domain Decomposition: Computational Fluid Dynamics

PRACTICAL SESSION 4: FORWARD DYNAMICS. Arturo Gil Aparicio.

International Conference Las Vegas, NV, USA March 7-9, 2014

Domain Decomposition: Computational Fluid Dynamics

Lab 6 - Ocean Acoustic Environment

Introduction to Matlab

ODEs occur quite often in physics and astrophysics: Wave Equation in 1-D stellar structure equations hydrostatic equation in atmospheres orbits

Using RecurDyn. Contents

CFD MODELING FOR PNEUMATIC CONVEYING

Lab 2: Introducing XPPAUT

[1] CURVE FITTING WITH EXCEL

Effect of Uncertainties on UCAV Trajectory Optimisation Using Evolutionary Programming

Scientific Computing for Physical Systems. Spring semester, 2018

Geophysics 224 B2. Gravity anomalies of some simple shapes. B2.1 Buried sphere

Deep Learning for Visual Computing Prof. Debdoot Sheet Department of Electrical Engineering Indian Institute of Technology, Kharagpur

Introduction to Matlab. Summer School CEA-EDF-INRIA 2011 of Numerical Analysis

Lectures & Excercises

AMSC/CMSC 460 Final Exam, Fall 2007

Isotropic Porous Media Tutorial

Transcription:

Mathematics for I Workpackage 5 - Ordinary Differential Equations Introduction During this laboratory you will be introduced to some of Matlab s facilities for solving ordinary differential equations (ode). Many mathematical models are based on differential equations and it is not always possible to find an analytical solution. When classical methods fail numerical techniques can be used to find an approximate solution that is often accurate enough for our needs. (As potential engineers you may like to think about what the term accurate enough really means). The iterative nature of numerical methods makes them ideally suited for software implementation and Matlab provides the technology for doing so, not to mention all the facilities for plotting results. In addition to using Matlab s ode functions, you will also have opportunity to write your own ode solver based on Euler s method. To this end, Matlab function files are introduced. These are a type of M-file that is in a function format and enables users to develop their own specialised commands to augment the set already provided by Matlab. Objectives By the end of this experiment you should be able to : write and execute Matlab function files implement Euler s Method for simple ode problems use Matlab s functions to solve ordinary differential equations comment on the sources of error found in numerical methods appreciate the accuracy and performance of the various numerical techniques used oprionally tackle a more difficult dynamical problem using ode s (the moon lander) What must I give in and when? A copy of all your Matlab function files consisting of the commands and a full explanation of the code using comments should be placed in your h:\maths1 directory. Suggested names for the files are given in the text below (highlighted in bold) and to ensure that your work is marked please make sure that the filenames used are exactly as given. Your files should be self-contained, providing appropriate help information and producing/plotting their results. You should create a file called WP5.m and use it to guide the assessor of this workpackage through the solutions that you have achieved. Assume that the assessor will run your file WP5 and with appropriate fprintf statements, figures and any other means, guide them in a user-friendly and helpful way through your the achievements in this exercise. Assessment To assess your work, your Script File WP5.m will be examined on the screen, and then run. The assessor may optionally look at the specific m files called for below. The grade you are given will depend on two things: A judgement of the quality of the MATLAB in your solutions. A judgement of how well the results are presented when your script file is run. The optional exercise at the end of this workpackage asks for an additional file moonlander.m, and is worth 0% of the grade. The best you can get without attempting it is 80%. All exercises must be completed by the end of Monday 8th December 00. 1

Mathematics for I Laboratory Work Matlab Function Files Function files increase the usefulness and flexibility of Matlab. They are user-defined functions that are a special kind of M-file. By allowing the user to create Matlab functions using the Matlab language itself you can create new problem-specific functions which have the same status as other Matlab functions. A brief description of Matlab functions and an example is given below. More information can be found from the Help Window. Open the window, click on the Contents tab and then navigate to MATLAB, Using MATLAB, Programming and Data Types, M-File Programming and then Functions. function a = my_function(x,y) % a = my_function(x,y) % a = x^ + y^ a = x.^ + y.^; Open a new M-file and copy the above text into it. From the File menu choose Save and save as my_function.m which should be the name suggested. When writing function M-files it is important that the filename is the same as that of the function. The structure of the first line is function [output1,output, outputn] = function_name(input1,input, inputm) where the word function is used to differentiate function files from the Matlab script files that you encountered in the previous workpackage. Input1, input etc are the function s input variables and output1, output, etc are the output variables; these variables may be scalars or vectors or matrices. The second and third lines are comments. It is good practice to make the first comment line echo the command line as this provides the information needed to run the function. Other comments can be added to explain the operation of the function. To run the function type >> c = my_function(3,4) Here the values 3 and 4 are passed to the input variables, the calculations performed and the value of a passed back at the end of the function. It s just as easy to pass variables to functions, for example >> x=; >> y = 3; >> c = my_function(x,y) The input and output variables are internal to the function and so changing them inside the function has no effect on the variable in Matlab s main workspace. Try modifying your function file so that is passed 3 input variables, a, b and c and returns output variables, d and e where d = a^ + b^; e = a + b + c; Save this function as my_function.m. More information about Matlab Functions can be found from the Help Window. Open the window, click on the Contents tab and then navigate to MATLAB, Using MATLAB, Programming and Data Types, M-File Programming and then Functions.

Mathematics for I Ordinary Differential Equation Exercises It s the end of the first semester and freezing cold. Unfortunately the heating in your University accommodation is turned off at 10:00pm. The Accommodation Office believes that the radiators will stay hot all night but you think otherwise. To determine what actually happens to the temperature over time Newton s Law of Cooling can be used, given by dθ = k( θ θs ), with θ = θ 0 at time t=0 where θ S is the temperature of the surroundings, k is a constant depending on the liquid and θ(t) is the temperature of the liquid at time t. Time is taken in minutes with t=0 minutes being 10:00pm at which the temperature θ 0 =80 0 C and θ S = 0 0 C. A suitable value for k is 0.1. Using this information solve this equation analytically to find the time taken for the radiator to decrease to 3 0 C. This exact solution can be used to evaluate the accuracy of numerical methods for solving ordinary differential equations. Matlab cannot solve ordinary differential equations analytically but it can use numerical techniques to find an approximate solution. In many instances (such as the advanced exercise below) an exact solution cannot be found and a numerical methods is the only practical approach. The first numerical technique that we will look at is Euler s method. This technique uses the instantaneous gradient to predict the value after a time step. Substituting the above values gives dθ/ = -0.1θ. In 1 minute the radiator will have cooled by 0.1*80 = 8 0 C, so the temperature after 1 minute is 80 8 = 7 0 C. The new temperature gradient dθ/ = -0.1*7 = 7. 0 C, so after another time step of 1 minute the temperature lowers to 7 7. = 64.8 0 C. For a fuller description of Euler s method see Croft, Davison and Hargraves pages 584-8. Matlab function that uses Euler s method to find a numerical solution for the length of time the radiator takes to cool down to 3 0 C is given below. Include your numerical solution as a comment in the function file you write below. Write a Matlab function file euler.m that uses Euler s method to find a numerical solution for the length of time the radiator takes to cool down to 3 0 C for a given initial temperature and step size. The function file should produce output vectors of time and temperature (t and y respectively) which can be plotted using the command plot(t,y);. Use the following for the first line of the function file function [t,y] = euler(init_temp,step) It is likely that you will need to use a loop within your function file, for example see below: while init_temp>3 %your code here: % using the current temperature, calculate the temperature after the next time step % and save the time and temperature in their respective vectors end One difficulty you may encounter is that you do not know the size of the vectors of time and temperature vectors initially, as the number time steps it takes to reach 3 0 C is what you are trying to find! A neat way around this problem is to append the new values on to the old values, thus forming a vector. For example t = [t time]; 3

Mathematics for I will append the new value of time on to the previous values when included in the while loop loop above. Temperature (y) can be treated likewise. To investigate the affect of step size on the accuracy of the solution find the time taken when the step size = 10 minutes, 1 minute and 0.1 minutes and add these to your file as comments. Modify the program so that the temperature of the surroundings (Ts) is included in the formula and is passed as an input variable together with the constant k and the temperature to stop at (Tend). Finally, include an additional input variable that defines the maximum number of iterations for the routine. If this maximum number is reached the program should terminate and display an appropriate error message. Save this file as euler.m Matlab s ODE solvers Matlab has its own set of ready-made ordinary differential equation solvers. The most widely applicable of these is ode45 based on the Runge-Kutta method, see the Helpdesk for further information. This technique is a fairly fast and accurate method, although it does not allow the programmer to fully control the step size and requires the time interval for the integration to be defined Ode45 requires that the equations to be solved are placed in a function file that is called by the ode45 function during its execution. For example, to solve Q5. (a) from your Mathematics notes, the equation y = cos t can be represented by the following function file. function dy = ode_demo(t,y) % example ode45 file for y = cos t dy = cos(t); The initial conditions and time span to solve over are provided when calling the ode45 function >>[t, y] = ode45( ode_demo,[0 0],1); Here, the equation is solved for t = 0 to 0, subject to initial condition that y(0) = 1. Use plot(t, y) to see the result. Use ode45 to find a solution to the radiator exercise above. Save your differential equation as ode_radiator.m and include the appropriate command line function call and the time to cool to 3 0 C as comments. How does this method compare with your Euler technique in terms of accuracy and easy of computation? 4

Mathematics for I Advanced Exercise For full marks in this workpackage, try the final exercise in this section given below. Without this the most you can achieve id an 80% grade in this workpackage. It is conceptually difficult but the solution is not (necessarily) lengthy and it s also fun! Moon Lander A spacecraft approaches a dense spherical body. It has a speed of 10 4 ms -1 when at an altitude of 10 6 metres above the surface. Its initial mass is 10 5 kilograms and its engines develop 10 7 Newtons of thrust. The craft is heading directly for the centre of the body which has a radius of 10 5 m and the product of its mass and the universal gravitational constant is 10 1 Newton metres per kilogram. The equation governing the spacecraft s motion is where m = mass of spacecraft y = altitude R = radius of body GM = 10 1 Nm /kg d y = Thrust GM m ( y + R) The spacecraft s engine uses fuel as it thrusts, so the mass of the craft changes when the engine is on. The rate of change is given by dm = 5 10 6 Thrust Because the mass is changing with time when the engine is on, this is a NONLINEAR problem that lacks a mathematical solution. The only way to solve it is with a numerical method. Your mission, should you choose to accept it, is to find the time at which the engine must be ignited to bring the vehicle to rest within 00m of the planet s surface. The first step to finding a solution is to reduce the above equations to a first order form that is suitable for numerical methods, see the first page for the Mathematics notes for Ordinary Differential Equations. Once this has been done both Euler s and the Runge-Kutta method used by ode45 can be used to find a solution. Note that sets of differential equations apply: one describing the motion before the engine is ignited, and one describing the motion afterwards. To obtain a solution to the problem try investigating the altitude that the spacecraft comes to rest (velocity=0) as a function of ignition time; this will get you close to the answer. Try writing your own Euler s method for this problem, saving it as euler_rocket.m. Does it seem likely that Euler s method is capable of providing a solution at all, let alone an accurate one? Next, try applying Matlab s Runge-Kutta ode solver, ode45, to this problem. You will probably have to create different M-file containing the differential equations before and after the engine is ignited. Use this method to try and find a solution by using the same approach as for Euler s method. To have this exercise marked, create the file moonlander.m to guide the assessor through your solution. Even if you have not succeeded fully, try to present your efforts and whatever results there are as best you can. 5