Polynomials, Curve Fitting and Interpolation. In this chapter will study Polynomials – functions of a special form that arise often in science and engineering.

Slides:



Advertisements
Similar presentations
259 Lecture 17 Working with Data in MATLAB. Overview  In this lecture, we’ll look at some commands that are useful for working with data!  fzero  sum,
Advertisements

1 Chapter 13 Curve Fitting and Correlation This chapter will be concerned primarily with two separate but closely interrelated processes: (1) the fitting.
1 Eng. Mohamed El-Taher Eng. Ahmed Ibrahim. 2 1.FUNCTION SUMMARY polyfun  Polynomial functions are located in the MATLAB polyfun directory. For a complete.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 ~ Curve Fitting ~ Least Squares Regression Chapter.
Chapter 15 Above: GPS time series from southern California after removing several curve fits to the data.
Chapter 2 Functions and Graphs
EGR 105 Foundations of Engineering I
Regression Analysis Using Excel. Econometrics Econometrics is simply the statistical analysis of economic phenomena Here, we just summarize some of the.
Excel Part III Curve-Fitting, Regression Section 8 Fall 2013 EGR 105 Foundations of Engineering I.
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.
Section 4.2 Fitting Curves and Surfaces by Least Squares.
Matlab Matlab is a powerful mathematical tool and this tutorial is intended to be an introduction to some of the functions that you might find useful.
Part 4 Chapter 13 Linear Regression
EGR 105 Foundations of Engineering I Fall 2007 – week 7 Excel part 3 - regression.
Exam #3 Review: Comprehensive Exam Class 14.2 Palm Matlab Book Ch. 1-5.
Chapter 5 Plotting Data Curve Fitting, Good Graphing Practices Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Dividing Polynomials.
Calibration & Curve Fitting
Matlab intro The Environment
Barnett/Ziegler/Byleen Finite Mathematics 11e1 Chapter 2 Review Important Terms, Symbols, Concepts 2.1. Functions Point-by-point plotting may be used to.
Physics 114: Lecture 17 Least Squares Fit to Polynomial
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.
Unit 3: Lesson 1: 3.1 Polynomial Basics (4-1)
Mathematics for Economics and Business Jean Soper chapter two Equations in Economics 1.
Least-Squares Regression
CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor
CMPS1371 Introduction to Computing for Engineers NUMERICAL METHODS.
1 Preliminaries Precalculus Review I Precalculus Review II
MATLAB INTRO CONTROL LAB1  The Environment  The command prompt Getting Help : e.g help sin, lookfor cos Variables Vectors, Matrices, and Linear Algebra.
Chapter 9 Function Approximation
Introduction to MATLAB for Engineers, Third Edition Chapter 6 Model Building and Regression PowerPoint to accompany Copyright © The McGraw-Hill Companies,
Measurement.
Unit 4: Modeling Topic 6: Least Squares Method April 1, 2003.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 4 Curve Fitting.
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.
Curve Fitting and Regression EEE 244. Descriptive Statistics in MATLAB MATLAB has several built-in commands to compute and display descriptive statistics.
Advanced Topics- Polynomials
Department of Mechanical Engineering, LSU Session IV MATLAB Tutorials Session IV Mathematical Applications using MATLAB Rajeev Madazhy
ES 240: Scientific and Engineering Computation. Chapter 13: Linear Regression 13. 1: Statistical Review Uchechukwu Ofoegbu Temple University.
Chapter 7 Polynomial and Rational Functions
CHAPTER 3 Model Fitting. Introduction Possible tasks when analyzing a collection of data points: Fitting a selected model type or types to the data Choosing.
Lecture 10 2D plotting & curve fitting Subplots Other 2-D Plots Other 2-D Plots Curve fitting © 2007 Daniel Valentine. All rights reserved. Published by.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers Chapter 5B Model.
Scientific Computing General Least Squares. Polynomial Least Squares Polynomial Least Squares: We assume that the class of functions is the class of all.
The numerator must always be 1 degree less than the denominator
11/20/2015ENGR 111A - Fall MatLab – Palm Chapter 5 Curve Fitting Class 14.1 Palm Chapter:
Recap Cubic Spline Interpolation Multidimensional Interpolation Curve Fitting Linear Regression Polynomial Regression The Polyval Function The Interactive.
Residuals Recall that the vertical distances from the points to the least-squares regression line are as small as possible.  Because those vertical distances.
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 © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 4 Chapter 15 General Least Squares and Non- Linear.
Chapter 13 Objectives Familiarizing yourself with some basic descriptive statistics and the normal distribution. Knowing how to compute the slope and intercept.
Curve Fitting Introduction Least-Squares Regression Linear Regression Polynomial Regression Multiple Linear Regression Today’s class Numerical Methods.
Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
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.
Chapter 4 More on Two-Variable Data. Four Corners Play a game of four corners, selecting the corner each time by rolling a die Collect the data in a table.
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.
Plotting in Excel Ken youssefi Engineering 10.
Chapter 2 Functions and Graphs
Introduction to Programming for Mechanical Engineers
Chapter 4: Basic Estimation Techniques
Chapter 4 Basic Estimation Techniques
Salinity Calibration fit with MATLAB
Lecture 10 2D plotting & curve fitting
MatLab – Palm Chapter 5 Curve Fitting
Presentation transcript:

Polynomials, Curve Fitting and Interpolation

In this chapter will study Polynomials – functions of a special form that arise often in science and engineering Curve fitting – finding exact function of a specified form that represents the data with the least amount of error Interpolation – estimating values between data points

POLYNOMIALS MATLAB represents a polynomial by a row vector First vector element is coefficient of x to highest power, i.e., an Second element is an-1 nth element is a1 Element n+1 is a0 MATLAB represents a polynomial of degree n by a vector of length n+1

Vector must include all polynomial coefficients, even those that are zero POLYNOMIALS

MATLAB function polyval computes the value of a polynomial p is vector of polynomial coefficients x is scalar, vector, or matrix of points at which polynomial should be evaluated For vector or matrix, polyval performs elementwise evaluation POLYNOMIALS

Roots of a Polynomial The roots of a polynomial are the values of the independent variable that make the polynomial be zero A polynomial of degree n has exactly n roots, though some may be repeated MATLAB function roots finds all of the roots of a polynomial

If you know the roots of a polynomial, you can get the polynomial's coefficients with p = poly( r ) where r is a vector of roots >> r = [ ]; >> p = poly( r ) p = >> roots( p ) % verify that get roots ans = Roots of a Polynomial

Addition, Multiplication, and Division of Polynomials Addition: To add (subtract) two polynomials, add (subtract) their vectors of coefficients If one vector is shorter, must stick enough zeroes in front of it so same size as longer

Multiplication: Multiply two polynomials with the built-in function conv, like so: c = conv( a, b ) where a and b are two vectors of polynomial coefficients and c is a vector of the coefficients of the product a and b can be different degrees Addition, Multiplication, and Division of Polynomials

Division: Divide two polynomials with the built-in function deconv, which has the form Addition, Multiplication, and Division of Polynomials

Can calculate derivative of a polynomial, product of polynomials, or quotient of polynomials with the MATLAB function polyder

[

CURVE FITTING Curve fitting is the process of adjusting a mathematical function so that it lays as closely as possible to a set of data points Can then use function as a mathematical model of data This section will study basic curve-fitting techniques and related MATLAB tools.

Curve Fitting with Polynomials; The polyfit Function Two general ways to fit a polynomial to data points 1. Polynomial must pass through every data point 2. Polynomial does not need to pass through every data point

Polynomials that pass through all the data points: Given n data points (xi,yi), can make a polynomial of degree n-1 that will pass through all n points. For example, Given two points, can write a linear equation (polynomial of degree one) y = mx + b that passes through both points Given three points, can write a quadratic equation (polynomial of degree two) y = ax2 + bx + c that goes through all three points

Polynomials that do not necessarily pass through any of the points: Given a set of n data points (xi,yi), can often make a polynomial of degree less than n-1 that may not pass through any of the points but still approximates the set overall Most common method of doing this is called the least-squares fit

To make a least-squares fit of a polynomial p(x) of degree n to a set of data points (xi,yi) 1. Compute the difference p(xi)-yi at each data point Difference is often called the residual or error 2. Square each difference 3. Sum the squares 4. Find the values of the n+1 coefficients of p(x) that minimize this sum

EXAMPLE

MATLAB function polyfit computes least-squares best fit of data points to a polynomial

When use polyfit on a set of m data points Can use any polynomial degree n such that n ≤ m-1 If n = m-1 the polynomial will go through all of the points A polynomial of degree m-1, or similar high degree, may not necessarily provide the best overall fit because it may deviate substantially between data points

polyfit – An example >> x = linspace(0,1,5) x = >> y = 1./(1+x) y = >> p1 = polyfit(x,y,4) p1 = >> plot(x,y,'o') >> f1 = polyval(p1,x) f1 = >> hold on >> plot(x,f1,'r--')

polyfit – Another example >> x = linspace(0,1,5) x = >> y = 1./(1+x) y = >> p2 = polyfit(x,y,2) p2 = >> plot(x,y,'o') >> f2 = polyval(p2,x) f2 = >> hold on >> plot(x,f2,'r--') Not bad at all!

polyfit – Another example The following script compares actual data points with different polynomial equations of degrees 1 to 4. data_x = linspace (1,100,10); data_y = [ ]; plot(data_x, data_y, '-o'); hold on p = polyfit(data_x, data_y, 1); plot(data_x, polyval(p,data_x), '--k'); p = polyfit(data_x, data_y, 2); plot(data_x, polyval(p,data_x), '--r'); p = polyfit(data_x, data_y, 3); plot(data_x, polyval(p,data_x), '--m'); p = polyfit(data_x, data_y, 4); plot(data_x, polyval(p,data_x), '--c'); legend ('Original data', '1st degree', '2nd degree', '3rd degree', '4th degree') hold off

polyfit – Another example

Often need to fit functions that are not polynomials. The four functions below are commonly used and can be converted to polynomials (in fact linear polynomials) through mathematical tricks. Can then use polyfit to fit them(read your book carefully) Curve Fitting with Functions Other than Polynomials

Call polyfit for the functions as shown The output p has two elements: p(1) is the coefficient m above and p(2) is b

A good way to tell if any of the four functions will be a good fit is to plot them with the axes indicated. If the data looks linear, use the corresponding function in polyfit

Remember the MATLAB functions that plot the axes different ways? plot – x linear, y linear semilogx – x logarithmic, y linear semilogy – x linear, y logarithmic loglog – x logarithmic, y logarithmic

Here is an example script trying the different axes scales to make the proper decision: data_x = linspace (1,100,10); data_y = [ ]; subplot (2,2,1); plot(data_x, data_y); title ('LINEAR'); subplot (2,2,2); semilogx(data_x, data_y, 'k'); title ('LOG IN X / LINEAR IN Y'); subplot (2,2,3); semilogy(data_x, data_y, 'm'); title ('LINEAR IN X / LOG IN Y'); subplot (2,2,4); loglog(data_x, data_y, 'g'); title ('LOGARITHMIC'); Curve Fitting with Functions Other than Polynomials

This one looks like the straighter curve, so an exponential function might be the best choice for this set of data.

Other considerations in choosing a function: Exponential functions Can't pass through origin Can only fit data that is all positive or all negative Logarithmic functions can't model points with x ≤ 0 Power function is 0 when x = 0 Reciprocal function can't model y = 0

INTERPOLATION Interpolation is estimating values between data points. MATLAB can do interpolation with polynomials or the Fourier transform Won't discuss Fourier-transform interpolation in this book

One-dimensional interpolation: linear interpolation is estimating value between two data points by connecting points with a straight line and then using value on line as estimated value INTERPOLATION

In linear interpolation Curve between two data points has constant slope In general, slope of curve changes at every data point Can get smoother interpolations by using quadratic or cubic splines, which are polynomials whose coefficients are based only on data points near interpolated point INTERPOLATION

MATLAB function interp1() does one-dimensional interpolation "one"

INTERPOLATION

THE BASIC FITTING INTERFACE MATLAB has a tool that lets you perform interpolation interactively. With it, you can Curve fit with polynomials up to degree 10 Compare fits with different polynomials by plotting on same graph Plot and compare residuals Calculate interpolated values

To activate tool (in the plot window) 1. Plot data points 2. Select Tools|Basic Fitting 3. Click right-arrow button twice so that window looks like that in Fig. 8-3 THE BASIC FITTING INTERFACE

Figure 8-3: The Basic Fitting Window

Select data If more than one data set plotted, lets you select which one to work on Can only work on one data set at a time, but can perform multiple fits simultaneously on that data Center and scale x data Data centered at zero mean and transformed so that standard deviation is one Check to display fits on figure Select types of fits you want MATLAB to perform and display

Show equations If checked, MATLAB displays equations of fits selected in box above field Plot residuals Indicate whether or not to plot fit residuals and style of residual plot Show norm of residuals Indicate whether or not to display norm of residuals. Norm is A measure of the quality of the fit Smaller norm means a better fit

Fit Select which fit to examine details of Coefficients and norm of residuals Show numerical values of coefficients in fit equation and value of norm Find y = f(x) Provide ability to examine fit values of manually- entered independent-variable values Fig. 8-4 is example of a Figure Window modified by changes in Basic Fitting Interface

Figure 8-4: A Figure Window modified by the Basic Fitting Interface

END OF LESSON