Lecture 11 Chap. 15. Outline-1 15.1 Interpolation – 15.1.1 Linear Interpolation – 15.1.2 Cubic Spline Interpolation – 15.1.3 Extrapolation 15.2 Curve.

Slides:



Advertisements
Similar presentations
Correlation and regression
Advertisements

Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 ~ Curve Fitting ~ Least Squares Regression Chapter.
©1999 BG Mobasseri 15/24/99 INTERPOLATION AND CURVE FITTING Etter: pp June 16, ‘99.
Quadratic Functions and Models
MATHEMATICAL METHODS.
Asymptotic error expansion Example 1: Numerical differentiation –Truncation error via Taylor expansion.
Data mining and statistical learning - lecture 6
1 Curve-Fitting Spline Interpolation. 2 Curve Fitting Regression Linear Regression Polynomial Regression Multiple Linear Regression Non-linear Regression.
Polynomial Functions A polynomial in x is a sum of monomials* in x.
CITS2401 Computer Analysis & Visualisation
EARS1160 – Numerical Methods notes by G. Houseman
ES 240: Scientific and Engineering Computation. InterpolationPolynomial  Definition –a function f(x) that can be written as a finite series of power functions.
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 30 Numerical Integration & Differentiation.
EGR 105 Foundations of Engineering I Fall 2007 – week 7 Excel part 3 - regression.
EGR 105 Foundations of Engineering I Fall 2007 – week 7 Excel part 3 - regression.
Petter Mostad Linear regression Petter Mostad
ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW III.
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 24 Regression Analysis-Chapter 17.
Regression Chapter 10 Understandable Statistics Ninth Edition By Brase and Brase Prepared by Yixun Shi Bloomsburg University of Pennsylvania.
Computer Graphics Recitation The plan today Least squares approach  General / Polynomial fitting  Linear systems of equations  Local polynomial.
Chapter 6 Numerical Interpolation
4.4 Adding and Subtracting Polynomials; Graphing Simple Polynomials
Math I, Sections 2.5 – 2.9 Factoring Polynomials
Derivatives and Differential Equations
Polynomial and Rational Functions
CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor
19.5 Numeric Integration and Differentiation
MECN 3500 Inter - Bayamon Lecture Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo
CMPS1371 Introduction to Computing for Engineers NUMERICAL METHODS.
1 Preliminaries Precalculus Review I Precalculus Review II
Introduction to MATLAB for Engineers, Third Edition Chapter 6 Model Building and Regression PowerPoint to accompany Copyright © The McGraw-Hill Companies,
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 4 Curve Fitting.
Lecture 22 - Exam 2 Review CVEN 302 July 29, 2002.
Copyright © 2014, 2010 Pearson Education, Inc. Chapter 2 Polynomials and Rational Functions Copyright © 2014, 2010 Pearson Education, Inc.
Recap Summary of Chapter 6 Interpolation Linear Interpolation.
Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
MECN 3500 Inter - Bayamon Lecture 9 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo
Biostatistics Lecture 17 6/15 & 6/16/2015. Chapter 17 – Correlation & Regression Correlation (Pearson’s correlation coefficient) Linear Regression Multiple.
Regression Regression relationship = trend + scatter
Chap. 11 Numerical Differentiation and Integration
Lecture 22 Numerical Analysis. Chapter 5 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.
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.
Copyright © 2015, 2008, 2011 Pearson Education, Inc. Section 6.1, Slide 1 Chapter 6 Polynomial Functions.
Basis of Mathematical Modeling LECTURE 3 Numerical Analysis with MATLAB Dr. N.K. Sakhnenko, PhD, Professor Associate.
Recap Functions with No input OR No output Determining The Number of Input and Output Arguments Local Variables Global Variables Creating ToolBox of Functions.
Basis Expansions and Generalized Additive Models Basis expansion Piecewise polynomials Splines Generalized Additive Model MARS.
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.
Introduction to Programming for Mechanical Engineers
Operations on Real Numbers
Part 5 - Chapter
Polynomials & Factoring
EEE 244-7: Curve Fitting.
Interpolation Methods
2.1 Equations of Lines Write the point-slope and slope-intercept forms
4.2 Polynomial Functions and Models
Chapter 7 Numerical Differentiation and Integration
Modelling data and curve fitting
Polynomials.
POLYNOMIAL INTERPOLATION
Numerical Analysis Lecture 26.
Interpolation Methods
Basis Expansions and Generalized Additive Models (2)
SKTN 2393 Numerical Methods for Nuclear Engineers
SKTN 2393 Numerical Methods for Nuclear Engineers
Numerical Analysis Lecture 21.
Ch 12.1 Graph Linear Equations
Curve Fitting Filling in the gaps.
Presentation transcript:

Lecture 11 Chap. 15

Outline Interpolation – Linear Interpolation – Cubic Spline Interpolation – Extrapolation 15.2 Curve Fitting – Linear Regression – Polynomial Regression

Outline Numerical Integration – Determination of the Complete Integral – Continuous Integration Problems 15.4 Numerical Differentiation – Difference Expressions – MATLAB Implementation

Interpolation We have at least two points with independent (think, horizontal axis) and dependent (think, vertical axis) components. We have another independent component, whose value is in between the smallest and the greatest of the previous independent components. We would like to know the corresponding dependent component.

Methods of Estimating the Result of Interpolation Linear Piecewise-linear Polynomial Cubic Spline Interpolation via Gaussian Processes Other

Quality Considerations Accuracy of interpolated value Amount of work to obtain an interpolated value Amount of initial data needed …

Example Interpolation From

Linear Interpolation If the initial points all lie on a line (y = mx + b) then use the equation of the line on newX. If there are only two initial points, they define a line.

Piecewise Linear Use adjacent pairs of initial points to define lines. With the point whose value is to be estimated by interpolation, choose the relevant defined line. Y = m(i) x(i) + b(i).

Polynomial If we had a polynomial for y in terms of x, – then, with an x to be interpolated, – we would evaluate the polynomial So, what’s left is to obtain a polynomial – For n points, there is one polynomial of degree n- 1 that touches all of the points – Can be computationally complex to find it

Spline Piecewise – polynomial – Low degree polynomials for intervals between furnished points – Connection from one interval to the next smooth Smaller error than linear interpolation (if linear is not perfect) Less work than perfect polynomial (if “real” polynomial is of higher degree than that of spline)

Cubic Spline The curve between each pair of points is a third-degree polynomial. There is a parameter t that varies from 0 to 1, and the distance from the starting point to the ending point goes from 0 to 100%. X = at 3 + b t 2 + c t + d Y = et 3 + f t 2 + g t + h So, need to know the values of a, b, …h

How to … Linear X = [ the independent axis values] Y = [the dependent axis values] Only works when X, Y pairs are all on the same line. answer_y = interp1(x,y, target_x)

How to…Piecewise Linear X = [ the independent axis values] Y = [the dependent axis values] whichInterval = 0; for i = 1:length(X) if target_x > X(i) – whichInterval = whichInterval+1; end Interval_x = [ x(whichInterval) x(whichInterval+1)] Interval_y = [ y(whichInterval) y(whichInterval+1)] answer_y = interp1(Interval_x, Interval_y, target_x)

How to…Cubic Spline answer_y = spline(x, y, target_x)

Extrapolation This is where one tries to guess beyond the limits of the available data. Be aware that error in this process can be significant. Cannot use interp1 Can use spline

15.2 Curve Fitting In polynomial interpolation we observed that for n points there is a polynomial of degree n-1 that includes all of the points. Suppose we believe that the points are not perfect, as in measured data. Suppose we choose a degree of polynomial less than n, and then choose some coefficients for the polynomial, such that the difference between the measured data and the resulting polynomial is “minimized”.

Polynomial Curve Fitting-1 Degree of polynomial is the largest exponent Polynomial in x: – f(x) = ax n + bx n-1 + cx n-2 … dx + e – has degree n – has n+1 coefficients – so, with n+2 choices, the polynomial is determined Choose/guess the degree from information about the problem.

Polynomial Curve Fitting -2 What constitutes a “good” fit, for a particular choice of degree, n? Least squares is one kind of measure of how good the fit is. If for each point x,y, we take the difference between the y of the point and the y of the polynomial curve, square the difference (yields a positive number) and add up all those squared differences, we get a measure of goodness of fit called least squares.

Linear Regression If in curve fitting, we choose the degree n to be 1, we are fitting by linear regression. To get MATLAB to determine the coefficients, we call polyfit with n=1, which looks like polyfit(x,y,1) Polyfit returns the coefficients in linearly decreasing order of power of the variable in the polynomial. If n = 1, f(x)= ax+b, and the first coefficient returned is a, and the second is b.

Polynomial Regression Suppose we choose a degree of polynomial, called n, > 1. There will be more coefficients. For example, n=3, the number of coefficients will be 4. coef = polyfit (x, y, n) Now that coef is set, it can be used. New_y = polyval(coef, new_y)

More degrees of freedom yields closer fit function viewFits() x = 0:5; fine_x = 0:.1:5; y = [ ]; for order = 2:5 y2=polyval(polyfit(x,y,order), fine_x); subplot(2,2,order-1) plot (x,y,'o', fine_x, y2) axis([ ]) ttl = sprintf('Degree %d Polynomial Fit',... order); title(ttl) xlabel('Time (sec)') ylabel('Temperature (degrees F)') end

15.3 Numerical Integration Using piecewise linear technique – Add areas from trapezoidal rule – K T = (b – a)/2n)(f(a) + 2f(x 1 ) + 2f(x 2 )… + 2f(x n-1 ) + f(b)) Using piecewise parabolic technique – Add areas from Simpson’s rule – K S = (b – a)/2n)(1/3)(f(a) + 4f(x 1 ) + 2f(x 2 ) + 4f(x 3 )+ … + 2f(x n-2 ) + 4f(x n-1 ) + f(b))

Numerical Integration Code function K = trapezoid(v,a,b) %h = trapezoid(v,a,b) K=(b-a)*(v(1)+v(end)+... 2*sum(v(2:end-1)))/(2*(length(v)-1)); function K = simpson(v,a,b) %h = simpson(v,a,b) K=(b-a)*(v(1)+v(end)+… 4*sum(v(2:2:end-1))+… 2*sum(v(3:2:end-2)))/ (3*length(v)-1));

Numerical Differentiation Forward difference: f’(x k ) = (f(x k ) – f( x k-1 ))/(x k – x k-1 ) Backward difference: f’(x k ) = (f(x k+1 ) – f( x k ))/(x k+1 – x k ) Centered difference: f’(x k ) = (f(x k+1 ) – f( x k-1 ))/(x k+1 – x k-1 ) Both forward and backward differences are first- order. They take differences of adjacent terms.

MATLAB function diff function diff returns a vector of differences between adjacent terms v(2)-v(1), v(3)-v(2), … Which of forward, backward is this? Could it be used for either one? Suppose we wanted centered. Could we use diff? Would we need to prepare by a step?

Forward Difference Code x=-7:0.1:9; f = polyval([0.0333,-0.3, ,16,0,-187.2,0],x); plot(x,f) hold on df = diff(f)./diff(x) plot(x(2:end),df, ‘g’) grid legend({‘f(x)’,’f ‘’(x)’})