Polynomial Deinition a unction () that can be written as a inite series o power unctions like n is a polynomial o order n n ( ) = A polynomial is represented by coeicient vector rom highest power. p=[3-5 -7 9] p() = 3 4-5 3 7 + + 9 n i= 0 a i i
Polynomial Operations poly(r) convert roots to a polynomial r=[ 3 ]; poly(r) roots(p) ind roots o a polynomial p=[ 3 4 ] roots(p) Y = polyval(p, ) returns the value o a polynomial, p(). P is a vector o length N+ whose elements are the coeicients o the polynomial in descending powers. p=[3-5 -7 9] p() = 3 4-5 3 7 + + 9
Polynomial Operations P = polyit(, y, n) Returns the least squares it coeicients o a polynomial p() o degree n P is o length N+. conv(p,p) multiply two polynomials p and p conv(p,p) [q r]=deconv(p,p) polynomials p divide by p, where q is quotient and r is remainder [q r]=deconv(p,p)
Polynomial Operations polyint(p,c) integrate o polynomial p with integration constant c (deault 0) polyint(p) polyint(p,) polyder(p) dierentiate polynomial p respective to >> polyder(p)
Curve Fitting Applications Estimating the value o points between discrete values Simpliying complicated unctions Methods Data are very precise curve passes through all points curve itting Data are just approimations curve represent a general trend o the data
Curve Fitting and Curve Fitting (linear or non-linear) Linear (most popular interpolation) Other (higher order polynomial, spline, nearest, )
Linear The linear interpolation is achieved by itting a line between two known data points The resulting ormula based on known points and and the values o the dependent unction at those points is: ()= ( )+ ( ) ( ) ( )
Quadratic (Polynomial) One problem that can occur with solving or the coeicients o a polynomial is that the system to be inverted is in the orm: n L n L M M O M M n n n L n n n L n n n n n n Matrices such as that on the let are known as Vandermonde matrices, and they are very ill-conditioned - meaning their solutions are very sensitive to round-o errors. The issue can be minimized by scaling and shiting the data. p p M p n p n ( ) ( ) = M n n ( ) ( )
Newton Interpolating Polynomials Newton Interpolating Polynomials Another way to epress a polynomial interpolation is to use Newton s interpolating polynomial. This is a achieved by an etension to linear interpolation ) )( 3( ) ( ) ( ) ( ) ( ) ( ) ( Newton Simple Order 3 b b b a a a nd b b a a st + + = + + = + = + = ( ) ( ) ( ) ( ) 3 3 3 3 ) ( ) ( ); ( b b b = = =
Newton Interpolating Polynomials (cont) Newton Interpolating Polynomials (cont) The second-order Newton interpolating polynomial introduces some curvature to the line connecting the points, but still goes through the irst two points. The resulting ormula based on known points,, and 3 and the values o the dependent unction at those points is: ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( )( ) 3 3 3 + + =
Generalization An (n-) th Newton interpolating polynomial has all the terms o the (n-) th polynomial plus one etra. The general ormula is: where n ()= b + b ( )+L+ b n ( ) ( )L n ( ) and the [ ] represent divided dierences. b = ( ) [ ] [ ] b =, b 3 = 3,, M [ ] b n = n, n,l,,
Divided Dierences Divided dierence are calculated as ollows: ( ) [ i, j ]= ( i) j i j [ i, j, k ]= [ i, j ] [ j, k ] i k [ n, n,l,, ]= [,,L, n n ] n, n,l, [ ] Divided dierences are calculated using n divided dierence o a smaller number o terms:
Eample 5. Do by hand Use the newtint unction
Lagrange Interpolating Polynomials Weighted average o the two values being connected The dierences between a simple polynomial and Lagrange interpolating polynomials or irst and second order polynomials is: Order Simple Lagrange st () = a + a () = L ( )+ L ( ) nd () = a + a + a 3 () = L ( )+ L ( )+ L 3 3 ( ) where the L i are weighting coeicients that are unctions o.
The irst-order Lagrange interpolating polynomial may be obtained rom a weighted combination o two linear interpolations, as shown. Lagrange Interpolating Polynomials (cont) The resulting ormula based on known points and and the values o the dependent unction at those points is: () = L ( )+ L ( ) L =, L = () = ( )+ ( )
Lagrange Interpolating Polynomials (cont) In general, the Lagrange polynomial interpolation or n points is: n ( )= L i i n i= ()( i ) where L i is given by: L i ()= n j= j i j i j
Eample 5. Solve by hand Use the lagrange unction
Etrapolation Etrapolation is the process o estimating a value o () that lies outside the range o the known base points,,, n. Etrapolation represents a step into the unknown, and etreme care should be eercised when etrapolating!
Etrapolation Hazards World population using a 7 th order polynomial etrapolation.
Oscillations Higher-order polynomials can not only lead to round-o errors due to ill-conditioning, but can also introduce oscillations to an interpolation or it where they should not be. In the igures below, the dashed line represents a unction, the circles represent samples o the unction, and the solid line represents the results o a polynomial interpolation:
Introduction to Splines An alternative approach to using a single (n-) th order polynomial to interpolate between n points is to apply lower-order polynomials in a piecewise ashion to subsets o data points. These connecting polynomials are called spline unctions. Splines minimize oscillations and reduce roundo error due to their lower-order nature.
Higher Order vs. Splines Splines eliminate oscillations by using small subsets o points or each interval rather than every point. This is especially useul when there are jumps in the data: a) 3 rd order polynomial b) 5 th order polynomial c) 7 th order polynomial d) Linear spline seven st order polynomials generated by using pairs o points at a time
Spline Development a) First-order splines ind straight-line equations between each pair o points that Go through the points b) Second-order splines ind quadratic equations between each pair o points that Go through the points Match irst derivatives at the interior points c) Third-order splines ind cubic equations between each pair o points that Go through the points Match irst and second derivatives at the interior points Note that the results o cubic spline interpolation are dierent rom the results o an interpolating cubic.
Spline Development Spline unction (s i ())coeicients are calculated or each interval o a data set. The number o data points ( i ) used or each spline unction depends on the order o the spline unction.
Cubic Splines While data o a particular size presents many options or the order o spline unctions, cubic splines are preerred because they provide the simplest representation that ehibits the desired appearance o smoothness. In general, the i th spline unction or a cubic spline can be written as: s i ()= a i + b i i ( )+ c i i ( ) + d i ( i ) 3 For n data points, there are n- intervals and thus 4(n-) unknowns to evaluate to solve all the spline unction coeicients. There is no one equation that can represent the whole spline unction on the domain
Piecewise in MATLAB MATLAB has several built-in unctions to implement piecewise interpolation. The irst is spline: yy=spline(,y,) This perorms cubic spline interpolation
Eample Generate data: = linspace(-,,9); y =./(+5*.^); Calculate 00 model points and determine not-a-knot interpolation = linspace(-, ); yy = spline(,y,); Calculate actual unction values at model points and data points, the 9-point (solid), and the actual unction (dashed), yr =./(+5*.^) plot(,y, o,, yy, -,,yr, -- )
MATLAB s interp Function While spline can only perorm cubic splines, MATLAB s interp unction can perorm several dierent kinds o interpolation: yi =interp(, y,i, method ) & y contain the original data i contains the points at which to interpolate method is a string containing the desired method: nearest - nearest neighbor interpolation linear - connects the points with straight lines spline - not-a-knot cubic spline interpolation pchip or cubic - piecewise cubic Hermite interpolation
Lab 5.9