MATLAB EXAMPLES Interpolation and Integration 58:111 Numerical Calculations Department of Mechanical and Industrial Engineering.

Slides:



Advertisements
Similar presentations
Splines and Piecewise Interpolation
Advertisements

Numerical Integration
MATLAB EXAMPLES Initial-value problems
ES 240: Scientific and Engineering Computation. Chapter 17: Numerical IntegrationIntegration  Definition –Total area within a region –In mathematical.
Chapter 15 Above: GPS time series from southern California after removing several curve fits to the data.
©1999 BG Mobasseri 15/24/99 INTERPOLATION AND CURVE FITTING Etter: pp June 16, ‘99.
Asymptotic error expansion Example 1: Numerical differentiation –Truncation error via Taylor expansion.
Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
Chapter 18 Interpolation The Islamic University of Gaza
CITS2401 Computer Analysis & Visualisation
ES 240: Scientific and Engineering Computation. InterpolationPolynomial  Definition –a function f(x) that can be written as a finite series of power functions.
Lecture 11 Chap. 15. Outline Interpolation – Linear Interpolation – Cubic Spline Interpolation – Extrapolation 15.2 Curve.
Numerical Integration Lecture (II)1
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 29 Numerical Integration.
Polynomial Interpolation
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 23 CURVE FITTING Chapter 18 Function Interpolation and Approximation.
Chapter 6 Numerical Interpolation
Numerical Operations S. Awad, Ph.D. M. Corless, M.S.E.E. E.C.E. Department University of Michigan-Dearborn Introduction to Matlab: Polynomial Manipulations.
Introduction  Today we are looking at how to interpret experimental data  Normally, data is acquired with random errors  How do we take the data and.
Chapter 4 Numerical Differentiation and Integration 1/16 Given x 0, approximate f ’(x 0 ). h xfhxf xf h )()( lim)('    x0x0 x1x1 h x1x1 x0x0.
1 NUMERICAL INTEGRATION Motivation: Most such integrals cannot be evaluated explicitly. Many others it is often faster to integrate them numerically rather.
1 Chapter 5 Numerical Integration. 2 A Review of the Definite Integral.
MECN 3500 Inter - Bayamon Lecture Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo
Integration Integration: is the total value, or summation, of f(x) dx over the range from a to b:
1 Numerical Analysis Lecture 12 Numerical Integration Dr. Nader Okasha.
CMPS1371 Introduction to Computing for Engineers NUMERICAL METHODS.
Chapters 5 and 6: Numerical Integration
Scientific Computing Linear and Quadratic Splines.
Curve Fitting and Interpolation: Lecture (I)
Hydroinformatics: Session4 Dr Ivan Stoianov Room 328B Dr Andrew Ireson (Room 304) Mr Juan Rodriguez-Sanchez (411A) Mr Baback.
Recap Summary of Chapter 6 Interpolation Linear Interpolation.
Curve Fitting and Regression EEE 244. Descriptive Statistics in MATLAB MATLAB has several built-in commands to compute and display descriptive statistics.
Polynomial Interpolation You will frequently have occasions to estimate intermediate values between precise data points. The function you use to interpolate.
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.
LINEAR ALGEBRA Matrix analysis Linear equations Eigenvalues and singular values Matrix functions.
Numerical Differentiation and Quadrature (Integration)
Computers in Civil Engineering 53:081 Spring 2003 Lecture #15 Spline Interpolation.
Recap Cubic Spline Interpolation Multidimensional Interpolation Curve Fitting Linear Regression Polynomial Regression The Polyval Function The Interactive.
Polynomials, Curve Fitting and Interpolation. In this chapter will study Polynomials – functions of a special form that arise often in science and engineering.
Mohiuddin Ahmad SUNG-BONG JANG Interpolation II (8.4 SPLINE INTERPOLATION) (8.5 MATLAB’s INTERPOLATION Functions)
MODEL FITTING jiangyushan. Introduction The goal of model fitting is to choose values for the parameters in a function to best describe a set of data.
Recap Functions with No input OR No output Determining The Number of Input and Output Arguments Local Variables Global Variables Creating ToolBox of Functions.
1 Lecture 8 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 4 Chapter 17 and 18 Interpolation.
MATLAB ® for Engineers, Holly Moore Fourth Edition, Global Edition © Pearson Education Limited 2015 All rights reserved. Figure 13.1 Interpolation between.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Chapter 20 Numerical Integration of Functions.
Lecture 29: Modeling Data. Data Modeling Interpolate between data points, using either linear or cubic spline models Model a set of data points as a polynomial.
MATLAB for Engineers 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
Trapezoidal Rule of Integration
Introduction to Programming for Mechanical Engineers
EEE 244-7: Curve Fitting.
Salinity Calibration fit with MATLAB
Lecture 5 Polynomial Approximation
Chapter 15 Curve Fitting : Splines
Direct Method of Interpolation
Chapter 7 Numerical Differentiation and Integration
MATH 2140 Numerical Methods
Lagrangian Interpolation
MATH 2140 Numerical Methods
NUMERICAL INTEGRATION
Lagrangian Interpolation
Splines and Piecewise Interpolation
POLYNOMIAL INTERPOLATION
Lagrangian Interpolation
Lagrangian Interpolation
SKTN 2393 Numerical Methods for Nuclear Engineers
Spline Interpolation Method
Numerical Integration
Lagrangian Interpolation
Presentation transcript:

MATLAB EXAMPLES Interpolation and Integration 58:111 Numerical Calculations Department of Mechanical and Industrial Engineering

Some useful functions polyfit Polynomial curve fitting p = polyfit(x,y,n), where p is the coefficient vector. polyval Polynomial evaluation y = polyval(p,x). interp1 One-dimensional data interpolation yi = interp1(x,y,xi,method), where method could be ‘linear’, ‘cubic’,’spline’ and ‘nearest’ interp2, interp3Two- and Three-dimensional interpolation trapzTrapezoidal numerical integration cumtrapzCumulative trapezoidal numerical integration quadNumerically evaluate integral, adaptive Simpson quadrature

Interpolation Suppose the original data set is: Here is the example to get the polynomial fitting by Lagrange interpolation: x-2012 y There are five sets of (x,y) above, polyfit can give the 4 th order polynomial form by Lagrange interpolation. To compare, we also use interp1 to give the more smooth fitting curve by piecewise cubic Hermite interpolation. The M-file (L_interperlation.m) is given to plot the fitting curve in the following: % Lagrange interpolating polynomial fitting x=[ ]; y=[ ]; [m n]=size(x) p=polyfit(x,y,n-1) x1=linspace(-2,2,50); y1=polyval(p,x1); y2=interp1(x,y,x1,'cubic'); plot(x,y,'o',x1,y1,'-',x1,y2,'.'); xlabel('x'),ylabel('y=f(x)') title ('Lagrange and Piecewise cubic Hermite interpolation')

Interpolation To run this example in MATLAB: >> L_interpolation p = The right figure shows the fitting curve and the original points (circle). The solid line is the 4 th order polynomial by lagrange interpolation. The dot curve is fitted by piecewise cubic Hermite interpolation. That means, the 4 th order polynomial is:

Integration Consider the following integration: The accurate integration is: Use the numerical integration, here only try trapezoidal method and Simpson method. Assuming the step size is h = 0.1. In MATLAB, first use the trapezoidal method: >>x=linspace(0,1,11); >> y=x.*exp(x.^2); >>s=trapz(x,y); >> num2str(s,'%20.9f') ans =

Integration To try Simpson’s method, we need write some codes (I_simpson.m): % Simpson's method of Numerical integration x=linspace(0,1,11); s=0.0; f = inline('x.*exp(x.^2)'); for k=1:5 f0=f(x(k*2-1)); f1=f(x(k*2)); f2=f(x(k*2+1)); s=s+(f0+4*f1+f2)*0.1/3.; end num2str(s,'%20.9f') Run this M-file in command window: >> I_simpson ans =

Integration Use the built-in function quad, which uses more accurate adaptive Simpson quadrature. The default error tolerance is 10e-6. >> f=inline('x.*exp(x.^2)') >> s=quad(f,0,1); >> num2str(s,'%20.9f') ans =

Compare the results of different methods (all keep 9 digits) in the following table: MethodSolutionError Exact Integration / Trapezoidal (h = 0.1) % Simpson’s (h = 0.1) % Adaptive Simpson % Integration-Summary To estimate error by step size h: For Trapezoidal method, it’s O(h 2 )=O(0.01) For Simpson’s method, it’s O(h 4 )=O(0.0001)