6&7-2 Dynamics, two examples of the use of ode45. Numeric Integration using trapz and quad/quadl functions. Readings: Matlab by Pratap Chapter 5.4,5.5.

Slides:



Advertisements
Similar presentations
Lecture 5.
Advertisements

Dynamics of a four-bar linkage
Linear Kinematics Chapter 3. Definition of Kinematics Kinematics is the description of motion. Motion is described using position, velocity and acceleration.
Numerical Differentiation and Quadrature (Integration) 1Daniel Baur / Numerical Methods for Chemical Engineers / Numerical Quadrature Daniel Baur ETH Zurich,
Friday, Jan. 29 th Agenda Collect Homework: “Isaac Newton” WS Finish section 7.3: –free fall, weight, terminal velocity, Newton’s 3 rd law In-Class Assignment.
Copyright © by Holt, Rinehart and Winston. All rights reserved. ResourcesChapter menu Law of Universal Gravitation Sir Isaac Newton (1642–1727) gave us.
Distance The length an object actually travels. How far you go. Scalar Displacement The change in position of an object. Length between start and finish.
APPLICATIONS OF DIFFERENTIATION
ENGG2013 Unit 22 Modeling by Differential Equations Apr, 2011.
The Islamic University of Gaza Faculty of Engineering Numerical Analysis ECIV 3306 Introduction.
Ch 2.1: Linear Equations; Method of Integrating Factors
Numerical Solutions of Ordinary Differential Equations
The Islamic University of Gaza Faculty of Engineering Civil Engineering Department Numerical Analysis ECIV 3306 Chapter 1 Mathematical Modeling.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Mathematical Modeling and Engineering Problem solving.
 Calculate the acceleration that this object experiences 30 kg 150 N.
A Mathematical Model of Motion
ACSL, POSTECH1 MATLAB 입문 CHAPTER 8 Numerical calculus and differential equations.
Chapter 9 Introduction to MATLAB for Engineers, Third Edition
CMPS1371 Introduction to Computing for Engineers NUMERICAL METHODS.
Physical Science Gravity. Objectives Explain that gravitational force becomes stronger as the masses increase and rapidly become weaker as the distance.
AP CALCULUS PERIODIC REVIEW. 1: Limits and Continuity A function y = f(x) is continuous at x = a if: i) f(a) is defined (it exists) ii) iii) Otherwise,
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
The Mathematics of Star Trek Lecture 3: Equations of Motion and Escape Velocity.
Engineering Computation and Simulation Conor Brennan Dublin City University EE317.
Dr. Hatim Dirar Department of Physics, College of Science Imam Mohamad Ibn Saud Islamic University.
Boundary Value Problems and Least Squares Minimization
Constructing the Antiderivative Solving (Simple) Differential Equations The Fundamental Theorem of Calculus (Part 2) Chapter 6: Calculus~ Hughes-Hallett.
Math 3120 Differential Equations with Boundary Value Problems
Kinematics Velocity and Acceleration. Motion Change in position of object in relation to things that are considered stationary Usually earth is considered.
Mathematical Modeling and Engineering Problem Solving
Equation of Motion for a Particle Sect nd Law (time independent mass): F = (dp/dt) = [d(mv)/dt] = m(dv/dt) = ma = m(d 2 r/dt 2 ) = m r (1) A 2.
Work, Energy, Power and Conservation Laws. In this week we will introduce the following concepts: o Kinetic energy of a moving object o Work done by a.
 Constructing the Antiderivative  Solving (Simple) Differential Equations  The Fundamental Theorem of Calculus (Part 2) Chapter 6: Calculus~ Hughes-
Sec. 4.1 Antiderivatives and Indefinite Integration By Dr. Julia Arnold.
MA/CS 375 Fall MA/CS 375 Fall 2002 Lecture 12.
Quadrature rules 1Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature Michael Sokolov ETH Zurich, Institut für Chemie- und.
Numerical Differentiation and Quadrature (Integration)
Mathematical Model of Motion Chapter 5. Velocity Equations Average velocity: v =  d/  t To find the distance traveled with constant or average velocity.
4.7 Improper Integrals 1 For integration, we have assumed 1. limits of integration are finite, 2. integrand f(x) is bounded. The violation of either of.
Motion in One Direction Chapter 2 Goals: motion, displacement, velocity, acceleration, freefall, acceleration due to gravity and equations to solve for.
Chapter 5 Integration. Indefinite Integral or Antiderivative.
SPH3U – Unit 2 Gravitational Force Near the Earth.
6.1 The Indefinite Integral
Numerical Analysis 3D Plots. A numerical method is a technique for computing a numerical approximation of the solution to a mathematical problem.
ACSL, POSTECH1 MATLAB 입문 CHAPTER 8 Numerical calculus and differential equations.
MTH 253 Calculus (Other Topics)
Terminal Velocity Predicting the rate an object will fall through air depending on mass, cross sectional area and other factors.
Chapter 2 Kinematics in One Dimension Mechanics – forces & motion Kinematics – describes motion Dynamics – causes of motion (forces)
2-2 What is a Matlab function? How does the plot function work? What Matlab functions are available to do Data Analysis? How can you create your own function.
Ch 2.1: Linear Equations; Method of Integrating Factors A linear first order ODE has the general form where f is linear in y. Examples include equations.
Work Readings: Chapter 11.
Applications of Differentiation Section 4.9 Antiderivatives
Acceleration, Weight and Mass. Weight Near the surface of the Earth, the pull of gravity on a body is practically constant and every falling body acquires.
Ch 1.1: Basic Mathematical Models; Direction Fields Differential equations are equations containing derivatives. The following are examples of physical.
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.
Gravity Chapter Gravity Law of Universal Gravitation- all objects in the universe attract each other through gravitational force Law of Universal.
5.3 Definite Integrals. Example: Find the area under the curve from x = 1 to x = 2. The best we can do as of now is approximate with rectangles.
4.3 Free Fall and the Acceleration due to Gravity
Differential Equations Copyright © Cengage Learning. All rights reserved.
Modeling First Order Systems in Simulink And Analyzing Step, Pulse and Ramp Responses SOEN385 Control Systems and Applications.
CMPSC 200 Fall 2013 Lecture 37 November 18, 2013.
Introduction to Programming for Mechanical Engineers
Chapter 12 Section 2 Gravity Objectives
Antiderivatives Chapter 4.9
ME 123 Computer Applications I Lecture 24: Character Strings 4/18/03
Numerical Integration:
Motion in One Dimension
LAW OF FALLING BODIES.
Presentation transcript:

6&7-2 Dynamics, two examples of the use of ode45. Numeric Integration using trapz and quad/quadl functions. Readings: Matlab by Pratap Chapter 5.4,5.5

6& Problem Definition Use Matlab to plot the velocity of a free-falling object. Assume that the object is near the earth’s surface, so that the force due to gravity is given by mass * g where 9.8 m/s 2. Further assume that air friction is present and that the force due to air friction satisfies F air friction = b * v 2, where b is constant and v is the velocity of the falling object (downward is negative velocity). 2. Refine, Generalize, Decompose the problem definition (i.e., identify sub-problems, I/O, etc.) Mass of object is 70Kg, acceleration due to gravity is -9.8 m/s 2 and the coefficient of air friction b =.25 Kg/s. At time = 0 assume v=0, that is, v(0) = 0 (initial condition)

6&7-4 m b v 2 -mg From Newton’s 2 nd law, the sum of the forces on the falling object equal it’s mass times acceleration: 2. (continued)

6& (continued) Using calculus we can rewrite the differential equation in the form: m bv 2 -mg and integration of both sides gives,

6& (continued) Since we can write tanh(x) as: m bv 2 -mg when x -> infinity tanh(x) -> 1 and so the falling body has a terminal velocity of:

6& Develop Algorithm (processing steps to solve problem) [t, v] = time, initial_condition); Rather than using calculus to solve this problem we can use a built-in Matlab function… ode45. The format of this function is: aux_function: user created function that computes the derivate time: a vector [start, stop] for the range of time of the solution initial_condition: initial value v(start) t: solution column vector of time values on range [start, stop] v: solution column vector velocity values at times t

6& Write the “Function" (Code) (instruction sequence to be carried out by the computer) Use the Matlab editor to create a file vprime.m. function vp = vprime(t,v) % function vp = vprime(t,v) % compute dv/dt m = 70; g = 9.8; b =.25; vp = -g +(b/m)*v.^2;

6& Test and Debug the Code To test our program in Matlab, we will plot velocity versus time for t=0 seconds to t=10 seconds, plot(t,v) 6. Run Code To run our program we will use ‘ode45’ as follows: >> [t, v] = [0,30], 0); >> plot(t,v) (See plot on next slide.) [t, v] = time, initial_condition);

As time increases the velocity levels out around m/s. This velocity is called the terminal velocity of the object. This agrees with the solution since v(infinity) = -sqrt(m*g/b) =

6& Problem Definition Use Matlab to plot both the velocity and position(height) of a free- falling object. 2. Refine, Generalize, Decompose the problem definition (i.e., identify sub-problems, I/O, etc.) Mass of object is 70Kg, acceleration due to gravity is 9.8 m/s 2 and the coefficient of air friction b =.25 Kg/s. Initial conditions: at time = 0 assume v=0 and y = 2000m. Plot the height y and the velocity v versus time for t = 0 to t = 30 seconds.

6& Develop Algorithm (processing steps to solve problem) The ODE describing the motion of a falling object is: m bv 2 -mg which is equivalent to the following system of ODEs:

6& Write the “Function" (Code) (instruction sequence to be carried out by the computer) Use the Matlab editor to create a file yvprime.m. Function yvprime has two inputs: t: a scalar value for time yv: a vector containing [y, v] values at time = t Function yvprime has one output: yvp: a vector containing [ dy/dt ; dv/dt] function yvp = yvprime(t, yv) % function yvp = yvprime(t, yv) m = 70; g = 9.8; b =.25; y = yv(1); v = yv(2); yvp = [v ; (-g +(b/m)*v.^2)];

6& Run Code To run our program we will use ‘ode45’ in a slightly different way as follows: [t, yv] = [0,30], [2000;0]); [t, yv] = time, initial_conditions); aux_function: user created function that computes the derivates time: a vector [start stop] for the range of time of the solution. initial_condition: initial value(s) [ y(start) ; v(start)] t: solution column vector of time values from [start, stop] yv: solution matrix with two columns [ y, v] representing values y in the first column and v in the second at time t

6& Test and Debug the Code To test our program in Matlab, we will plot velocity versus time >> plot(t,yv( :, 2 )) and we will plot y versus time, >> plot(t,yv( :, 1))

6& Test and Debug the Code Matlab produces a discretized solution >> yv >> t

6&7-17 Matlab offers a family of ODE solvers that use different methods to solve ODEs: ode45, ode15i, ode15s, ode23, ode23s, ode23t, ode23tb, ode113 Matlab does NOT guarantee that the solution any of the solvers produces is accurate. Knowledge that a particular solver will produce an accurate solution for a given ODE is beyond the scope of this course. CS 357 / CS 457 are courses in numerical analysis that cover methods of solving ODEs.

6&7-18 Most integrals arising from solutions of problems in engineering and the physical sciences cannot be represented in "closed form"- they must be evaluated numerically. For a function of a single variable, we seek an approximation to the area "under" the curve: a b Sum of the “signed” areas  f(x)dx a b  x f(x) + - Definite Integral The Matlab functions: quad (quad8) and trapz only apply to continuous functions f(x) of one variable - x ( a scalar).

6&7-19 f(x) x 0 = ax1x1 x n = bx2x2 x3x3 X n-1... In this case, we approximate the integral by adding the areas of a set of approximating rectangles. y x Approximation of f(x) by using constant functions on the intervals [x k-1, x k ] (not a good approximation). y1y1 y2y2 y3y3 ynyn  f(x)  f(x k )x k  1  x  x k,k  1,2, ,n

6&7-20 In this case, we approximate the integral by adding the areas of a set of approximating trapezoids. f(x) x =a 0 x 1 x =b n 2 x n-1 x... y0y0 y1y1 y2y2 Approximation of f(x) by using a linear function on the intervals [x k-1, x k ] (a better approximation). y x Trapezoidal Rule

6&7-21 In this case, we approximate the integral by adding the areas under a set of approximating parabolas. Approximation of f(x) by using a quadratic function on the intervals [x k-1, x k+1 ] ( better approximation). x Simpson's Rule (parabola) x k x k+1 x k-1 y y=f(x)

6&7-22 The two built-in Matlab functions (we will use in CS101) for integration are trapz and quad. The function trapz trapezoidal rule (Pratap p. 152) is used when we don’t know f(x) explicitly but we have a vector x which is a partition of the interval [a,b] and a vector y = f(x). That is, we know the y values of f(x) only for some discrete set of x values. We can use quad(Pratap 5.4 adaptive Simpson’s Rule) or quadl (Pratap 5.4 adaptive Lobatto) when we know the function f(x). That is, f(x) is a built-in Matlab function or a user defined function.

6&7-23 Example: Use Matlab to compute the integral: f(x)dx a b  where f(x) = sin(x) and a = 0, b = pi. >> format long >> x = linspace(0,pi,1000); >> y = sin(x); >> trapz(x,y) ans=

6&7-24 Example: Use Matlab to compute the integral: f(x)dx a b  where f(x) = sin(x) and a = 0, b = pi. >> ans=

6&7-25 We can use the Matlab function ode45 to solve a system of ordinary (not partial) differential equations. For numeric integration we can use quadl when we know the function f(x). The function trapz is used when we don’t know f(x) explicitly.