ACSL, POSTECH1 MATLAB 입문 CHAPTER 8 Numerical calculus and differential equations.

Slides:



Advertisements
Similar presentations
Numerical Integration
Advertisements

CSE 123 Symbolic Processing. Declaring Symbolic Variables and Constants To enable symbolic processing, the variables and constants involved must first.
Numerical Differentiation and Quadrature (Integration) 1Daniel Baur / Numerical Methods for Chemical Engineers / Numerical Quadrature Daniel Baur ETH Zurich,
Ordinary Differential Equations
MATHEMATICAL METHODS.
Lecture 18 - Numerical Differentiation
Chapter 4 Roots of Equations
Chapter 19 Numerical Differentiation §Estimate the derivatives (slope, curvature, etc.) of a function by using the function values at only a set of discrete.
Chapter 1 Introduction The solutions of engineering problems can be obtained using analytical methods or numerical methods. Analytical differentiation.
1 Chapter 8 Techniques of Integration Basic Integration Formulas.
Numerical Solutions of Ordinary Differential Equations
Ordinary Differential Equations Final Review Shurong Sun University of Jinan Semester 1,
1 Chapter 9 Differential Equations: Classical Methods A differential equation (DE) may be defined as an equation involving one or more derivatives of an.
Differential Equations and Boundary Value Problems
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.
Numerical Solution of Ordinary Differential Equation
CISE301_Topic7KFUPM1 SE301: Numerical Methods Topic 7 Numerical Integration Lecture KFUPM Read Chapter 21, Section 1 Read Chapter 22, Sections 2-3.
CISE301_Topic71 SE301: Numerical Methods Topic 7 Numerical Integration Lecture KFUPM (Term 101) Section 04 Read Chapter 21, Section 1 Read Chapter.
Derivatives and Differential Equations
Professor Walter W. Olson Department of Mechanical, Industrial and Manufacturing Engineering University of Toledo Solving ODE.
Graph quadratic equations. Complete the square to graph quadratic equations. Use the Vertex Formula to graph quadratic equations. Solve a Quadratic Equation.
CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor
MECN 3500 Inter - Bayamon Lecture Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo
Techniques of Integration
Chapter 9 Introduction to MATLAB for Engineers, Third Edition
CMPS1371 Introduction to Computing for Engineers NUMERICAL METHODS.
Chapters 5 and 6: Numerical Integration
ORDINARY DIFFERENTIAL EQUATION (ODE) LAPLACE TRANSFORM.
First Day of School Day 1 8/19/2013 Assignment Objectives:
More U-Substitution February 17, Substitution Rule for Indefinite Integrals If u = g(x) is a differentiable function whose range is an interval.
Foundations Basics: Notation, and other things Algebraic manipulations Indices, Logs, Roots and Surds Binomial expansion Trigonometric functions Trigonometric.
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.
Chapter 9 Numerical Integration Flow Charts, Loop Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Chapter 6 Finding the Roots of Equations
Scientific Computing Linear Least Squares. Interpolation vs Approximation Recall: Given a set of (x,y) data points, Interpolation is the process of finding.
Ordinary Differential Equations
Department of Mechanical Engineering, LSU Session IV MATLAB Tutorials Session IV Mathematical Applications using MATLAB Rajeev Madazhy
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
Numerical Methods for Solving ODEs Euler Method. Ordinary Differential Equations  A differential equation is an equation in which includes derivatives.
Numerical Methods for Engineering MECN 3500
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.
Week 6 Second Order Transient Response. Topics Second Order Definition Dampening Parallel LC Forced and homogeneous solutions.
Numerical Differentiation and Quadrature (Integration)
The previous mathematics courses your have studied dealt with finite solutions to a given problem or problems. Calculus deals more with continuous mathematics.
CHAPTER 3 NUMERICAL METHODS
Newton’s Method, Root Finding with MATLAB and Excel
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.
ACSL, POSTECH1 MATLAB 입문 CHAPTER 8 Numerical calculus and differential equations.
Antiderivatives and Indefinite Integration
Techniques for Numerical Integration
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 5 Integration and Differentiation.
ERT 210/4 Process Control & Dynamics DYNAMIC BEHAVIOR OF PROCESSES :
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.
Chapters 5 and 6: Numerical Integration Code development trapezoid rule Simpson’s rule Gauss quadrature Laguerre quadrature Analysis changing the variable.
SE301_Topic 6Al-Amer20051 SE301:Numerical Methods Topic 6 Numerical Integration Dr. Samir Al-Amer Term 053.
Computational Physics (Lecture 3) PHY4370. Interpolation Computer is a system with finite number of discrete states. – In numerical analysis, the results.
DYNAMIC BEHAVIOR OF PROCESSES :
CMPSC 200 Fall 2013 Lecture 37 November 18, 2013.
Basic Definitions and Terminology
FE Exam Tutorial
DIFFERENTIATION & INTEGRATION
Introduction to Programming for Mechanical Engineers (ME 319)
Chapter 3: Polynomial Functions
MATH 2140 Numerical Methods
SKTN 2393 Numerical Methods for Nuclear Engineers
Presentation transcript:

ACSL, POSTECH1 MATLAB 입문 CHAPTER 8 Numerical calculus and differential equations

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical calculus and differential equations 2 Review of integration and differentiation Engineering applications  Acceleration and velocity:  Velocity and distance:  Capacitor voltage and current:  Work expended: A ab x f(x)

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical calculus and differential equations 3 Integrals Properties of integrals Definite integrals Indefinite integrals This week's content handles definite integrals only the answers are always numeric see chapter 9

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical calculus and differential equations 4 Improper integrals and singularities Improper integrals singularity h 1-

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical calculus and differential equations 5 Derivatives Integration differentiation example : product rule : quotient rule : chain rule 1) 2) 3)

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical calculus and differential equations 6 Numerical integration Rectangular integration trapezoidal integration Numerical integration functions CommandDescription quad (‘function’,a,b,tol) Uses an adaptive Simpson’s rule to compute the integral of the function ‘function’ with a as the lower integration limit and b as the upper limit. The parameter tol is optional. Tol indicates the specified error tolerance. quadl (‘function’, a,b,tol) Uses Lobatto quadrature to compute the integral of the function ‘function’. The rest of the syntax is identical to quad. trapz (x,y) Uses trapezoidal integration to compute the integral of y with respect to x, where the array y contains the function values at the points contained in the array x. y x a b y=f(x) y x a b ··· (exact solution) (use of the trapz function)

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical calculus and differential equations 7 Rectangular, Trapezoidal, Simpson Rules Rectangular rule  Simplest, intuitive  wi = 1  Error=O(h) Mostly not enough! Trapezoidal rule  Two point formula, h=b-a  Linear interpolating polynomial Simpson’s Rule  Three point formula, h=(b-a)/2  Quadratic interpolating polynomial  Lucky cancellation due to right-left symmetry  Significantly superior to Trapezoidal rule  Problem for large intervals -> Use the extended formula x 0 =a x N =b f(x) x1x1 x2x2 f(x 1 ) f(x 2 ) x 0 =a x 1 =b f(x) f0f0 f1f1

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical calculus and differential equations Matlab's Numerical Integration Functions trapz(x,y) When you have a vector of data  trapezoidal integration method  not as accurate as Simpson's method  very simple to use quad('fun',a,b,tol)When you have a function  adaptive Simpson’s rule  integral of ’fun’ from a to b  tol is the desired error tolerance and is optional quad1('fun',a,b,tol) Alternative to quad  adaptive Lobatto integration  integral of ’fun’ from a to b  tol is the desired error tolerance and is optional 8

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical calculus and differential equations 9 Comparing the 3 integration methods The answer is A1=A2=0.6667, A3= test case: Trapezoid Method: x=linspace(0,pi, 10); y=sin(x); trapz(x,y); (exact solution) ( Simpson's Method: quad('sin',0,pi); Lobatto's Method quadl('sin',0,pi);

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical calculus and differential equations Integration near a Singularity Trapezoid: x=[0:0.01:1]; y=sqrt(x); A1=trapz(x,y); Simpson: A2=quad('sqrt',0,1); Lobatto: A3=quadl('sqrt',0,1); 10 (The slope has a singularity at x=0)

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical calculus and differential equations Using quad( ) on homemade functions 11 1) Create a function file: function c2 = cossq(x) % cosine squared function. c2 = cos(x.^2); Note that we must use array exponentiation. 2) The quad function is called as follows: quad('cossq',0,sqrt(2*pi)) 3) The result is

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical calculus and differential equations Problem 1 and 5 -- Integrate Hint: position is the integral of velocity*dt Hint: Work is the integral of force*dx 12

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical calculus and differential equations Problem 11 First find V(h=4) which is the Volume of the full cup Hint: Flow = dV/dt, so the integral of flow (dV/dt) from 0 to t = V(t) Set up the integral using trapezoid (for part a) and Simpson (for b) Hint: see next slide for how to make a vector of integrals with changing b values So you can calculate vector V(t), i.e. volume over time for a given flow rate  V = quad(....., 0, t) where t is a vector of times and then plot and determine graphically when V crosses full cup 13

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical calculus and differential equations To obtain a vector of integration results: For example,  sin(x) is the integral of the cosine(z) from z=0 to z=x In matlab we can prove this by calculating the quad integral in a loop: for k=1:101 x(k)= (k-1)* pi/100; % x vector will go from 0 to pi sine(k)=quad('cos',0,x(k)); % this calculates the integral from 0 to x end plot(x, sine) % this shows the first half of a sine wave % calculated by integrating the cosine 14

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical calculus and differential equations Problem 14 Hint: The quad function can take a vector of values for the endpoint Set up a function file for current Set up a vector for the time range from 0 to.3 seconds Then find v = quad('current',0,t) will give a vector result and plot v 15

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical calculus and differential equations 16 Numerical differentiation x1x1 x2x2 x3x3 y1y1 y2y2 y3y3 ΔxΔx ΔxΔx y=f(x) True slope A B C Δx 0 : backward difference : central difference : forward difference

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical calculus and differential equations 17 The diff function The diff Function d= diff (x) Backward difference & central difference method example example x=[5, 7, 12, -20]; d= diff(x) d =

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical calculus and differential equations Try that: Compare Backward vs Central Construct function with noise x=[0:pi/50:pi]; n=length(x); % y=sin(x) +/-.025 random error y=sin(x) +.05*(rand(1,51)-0.5); td=cos(x); % true derivative Backward difference using diff: d1= diff(y)./diff(x); subplot(2,1,1) plot(x(2:n),td(2:n),x(2:n),d1,'o'); xlabel('x'); ylabel('Derivative'); axis([0 pi -2 2]) title('Backward Difference Estimate') Central Difference d2=(y(3:n)-y(1:n-2))./(x(3:n)-x(1:n-2)); subplot(2,1,2) plot(x(2:n-1),td(2:n-1),x(2:n-1),d2,'o'); xlabel('x'); ylabel('Derivative'); axis([0 pi -2 2]) title('Central Difference Estimate'); 18

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical calculus and differential equations Problem 7: Derivative problem Hint: velocity is the derivative of height 19

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical calculus and differential equations Problem 17 20

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical calculus and differential equations 21 Polynomial derivatives -- trivia b = polyder (p) p = [a 1,a 2,…,a n ] b = [b 1,b 2,…,b n-1 ] b = polyder (p1,p2) [num, den] = polyder(p2,p1) Example p1= 5x +2 p2=10x 2 +4x-3 Result: der2 = [10, 4, -3] prod = [150, 80, -7] num = [50, 40, 23] den = [25, 20, 4] CommandDescription d=diff(x)Returns a vector d containing the differences between adjacent elements in the vector x. b=polyder(p)Returns a vector b containing the coefficients of the derivative of the polynomial represented by the vector p. b=polyder(p1,p2)Returns a vector b containing the coefficients of the polynomial that is the derivative of the product of the polynomials represented by p1 and p2. cf. equivalent comment: b=polyder(conv(p1,p2)) [num, den]= polyder(p2,p1) Returns the vector num and den containing the coefficients of the numerator and denominator polynomials of the derivative of the quotient p 2 /p 1, where p1 and p2 are polynomials. Numerical differentiation functions

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical calculus and differential equations 22 Analytical solutions to differential equations(1/6) Solution by Direct Integration  Ordinary differential equation (ODE) example  Partial differential equation (PDE) -- not covered

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical calculus and differential equations 23 Analytical solutions to differential equations(2/6) Oscillatory forcing function A second-order equation Forcing function example

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical calculus and differential equations 24 Analytical solutions to differential equations(3/6) Substitution method for first-order equations Characteristic equation Characteristic root ( ), to find A Solution, Free response ∵ The solution y(t) decays with time if τ>0 τ is called the time constant. suppose for M at t=0 Such a function is the step function ( ), Forced response Natural (by Internal Energy) v.s. Forced Response (by External Energy) Transient (Dynamics-dependent) v.s. Steady-state Response (External Energy-dependent)

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical calculus and differential equations Problem 18 – solve on paper then plot (next week we solve with Matlab) Use the method in previous slide 25

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical calculus and differential equations Problem 21 – solve on paper then plot (next week we solve with Matlab) Re-arrange terms: mv' + cv = f, OR (m/c) v' + v = f/c now it's in the same form as 2 slides back 26

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical calculus and differential equations 27 Analytical solutions to differential equations(4/6) Nonlinear equations Substitution method for second order equations(1/3) example () general solution suppose that solution 1)

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical calculus and differential equations 28 Analytical solutions to differential equations(5/6) Substitution method for second order equations(2/3) ( ) general solution Euler’s identities period frequency 2) 3) () 1. Real and distinct: s 1 and s Real and equal: s Complex conjugates:

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical calculus and differential equations 29 Analytical solutions to differential equations(6/6) Substitution method for second order equations(3/3) 1.real, distinct roots: m=1,c=8, k=15. characteristic roots s=-3, complex roots: m=1,c=10,k=601 characteristic roots 3. unstable case, complex roots: m=1,c=-4,k=20 characteristic roots 4. unstable case, real roots: m=1,c=3,k=-10 characteristic roots s=2,-5.

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical calculus and differential equations Problem 22 Just find the roots to the characteristic equation and determine which form the free response will take (either 1, 2, 3 or 4 in previous slide) This alone can be a helpful check on matlab's solutions—if you don't get the right form, you can suspect there is an error somewhere in your solution 30

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical calculus and differential equations Next Week: we learn how to solve ODE's with Matlab 31