polynomials,curvefitting, and interpolation

24
BY Uday Saikia POLYNOMIALS,CURVEFITTING, AND INTERPOLATION

Upload: uday-saikia

Post on 14-Nov-2014

299 views

Category:

Education


2 download

DESCRIPTION

POLYNOMIALS,CURVEFITTING, AND INTERPOLATION

TRANSCRIPT

Page 1: POLYNOMIALS,CURVEFITTING, AND INTERPOLATION

BY

Uday Saikia

POLYNOMIALS,CURVEFITTING, AND INTERPOLATION

Page 2: POLYNOMIALS,CURVEFITTING, AND INTERPOLATION

Polynomials are functions that have the form :

Here coefficients are real numbersn= non-negative integer. It is the degree or order of the

polynomial

Page 3: POLYNOMIALS,CURVEFITTING, AND INTERPOLATION

>> Value of a Polynomial:

polyval (p , x)Here p = A vector with the co-efficients of

the polynomialx = It is a number , or a variable that

has an assigned value , or a computable expression

Page 4: POLYNOMIALS,CURVEFITTING, AND INTERPOLATION

>> Calculation of Polynomials with MATLABProblem 1:f(x)= (a) Calculate f(9)(b) Plot the polynomial for -1.5≤x≤6.7

Page 5: POLYNOMIALS,CURVEFITTING, AND INTERPOLATION

Sol : f(x)=

>> p=[1 -12.1 40.59 -17.015 -71.95 35.88]>>polyval(p,9)

ans = 7.2611e+003

>>x=[-1.5:0.1:6.7];>>y=poyval(p,x);>>Plot(x,y)

Page 6: POLYNOMIALS,CURVEFITTING, AND INTERPOLATION
Page 7: POLYNOMIALS,CURVEFITTING, AND INTERPOLATION

>>Roots of a polynomial:r = roots(p)

r=It is a column vector with the roots of the polynomial

p=It is row vector with the co-efficients of the polynomial

>> p=[1 -12.1 40.59 -17.015 -71.95 35.88]>> r=roots(p)

r = 6.5000 4.0000 2.3000 -1.2000 0.5000

Page 8: POLYNOMIALS,CURVEFITTING, AND INTERPOLATION

>> When the roots of a polynomial are known, the poly command can be used for determining the coefficients of the polynomial.

>> r=[6.5 4 2.3 -1.2 0.5];>> z=poly(r)

z =

1.0000 -12.1000 40.5900 -17.0150 -71.9500 35.8800

Page 9: POLYNOMIALS,CURVEFITTING, AND INTERPOLATION

ADDITION , MULTIPLICATION & DIVISION OF POLYNOMIALS:

>>Add the two functions:

40 , and6

>> f1=[3 15 0 -10 -3 15 -40];>> f2=[3 0 -2 -6];>> f=f1+[0 0 0 f2]

f =

3 15 0 -7 -3 13 -46

Page 10: POLYNOMIALS,CURVEFITTING, AND INTERPOLATION

40 , and6

Multiply them.

>> f1=[3 15 0 -10 -3 15 -40];>> f2=[3 0 -2 -6];>> m=conv(f1,f2)

m =

9 45 -6 -78 -99 65 -54 -12 -10 240

Page 11: POLYNOMIALS,CURVEFITTING, AND INTERPOLATION

40 , and6

Divide by

>> f1=[3 15 0 -10 -3 15 -40];>> f2=[3 0 -2 -6];>> [a b]=deconv(f1,f2)

a =

1.0000 5.0000 0.6667 2.0000

b =

0 0 0 0 28.3333 23.0000 -28.0000

Page 12: POLYNOMIALS,CURVEFITTING, AND INTERPOLATION

#Derivatives of Polynomials:

+4, +5Find out the Derivatives of +4, (+4)(+5) and >> f1=[3 -2 4];>> f2=[1 0 5];>> k=polyder(f1)k =

6 -2

>> d=polyder(f1,f2)d =

12 -6 38 -10

>> [n d]=polyder(f1,f2)n =

2 22 -10

d =

1 0 10 0 25

6x-2

10

2𝑥2+22𝑥−10𝑥4+10 𝑥2+25 

Page 13: POLYNOMIALS,CURVEFITTING, AND INTERPOLATION

#Curve FittingIt is a process of fitting a function to a set of data

points. p=polyfit(x,y,n)here p=A vector of the co-

efficients of the polynomial that fits the data

x=A vector with the horizontal co- ordinate of the data points

y= A vector with the vertical co-ordinate of the data points

n=Degree of polynomial

Page 14: POLYNOMIALS,CURVEFITTING, AND INTERPOLATION

# INTERPOLATION:

It is estimation of values between data points.

yi = interpl (x, y, xi, ‘method’)

Here,

yi = It is Interpolated value

x = It is a vector with horizontal co-ordinate of the

input data points

y = It is a vector with vertical co-ordinate of the input

data points

xi = Horizontal co-ordinate of the interpolation point

‘nearest’ : returns the value of the data point that is nearest to the interpolated point‘linear’ : uses linear spline interpolation‘spline’ : uses cubic spline interpolation‘pchip’ : uses piecewise cubic Hermite interpolation

Page 15: POLYNOMIALS,CURVEFITTING, AND INTERPOLATION

** Specification method is optional. If no method is specified, the default is ‘linear’

** ‘spline’ method can give large errors if the input data pints are non-uniorm

Page 16: POLYNOMIALS,CURVEFITTING, AND INTERPOLATION

Problem : The following data points are the points of the function cos(2x).Use linear,spline and pchip interpolation methods to calculate the value of y between the points. Make a figure for each of the interpolation methods.

x 0 1 2 3 4 5

y 1.0 -0.6242

-1.4707

3.2406

-0.7366

-6.3717

Page 17: POLYNOMIALS,CURVEFITTING, AND INTERPOLATION

>> x=[0:1.0:5];

y=[1.0 -0.6242 -1.4707 3.2406 -0.7366 -6.3717];

xi=[0:0.1:5];

yilin=interpl(x,y,xi,'linear');

yispl=interpl(x,y,xi,'spline');

yipch=interpl(x,y,xi,'pchip');

yfun=1.5.^xi*cos(2*xi);

subplot(1,3,1)

plot(x,y,'o'xi,yfun,xi,yilin,'--');

subpolt(1,3,2)

plot(x,y,'o',xi,yfun,xi,yispl,'--');

subplot(1,3,3)

plot(x,y,'o',xi,yfun,xi,yipch,'--')

Page 18: POLYNOMIALS,CURVEFITTING, AND INTERPOLATION

# The Basic Fitting Interface:

It is a tool that can be used to perform curve fitting and interpolation interactively. By using the interface, the user can :

*Fit the curve to the data points with the polynomials of various degrees up to 10, and with Spline interpolation method

*Plot the various fits on the plot simultaneously so that they can be compared

*Calculate the value of specific points with the various fits

*Add the equations of the polynomials to the plot

Page 19: POLYNOMIALS,CURVEFITTING, AND INTERPOLATION

3 – DIMENSIONAL PLOTS:

Line Plots:

A three dimensional line plot is a line that is obtained by connecting points in a three-dimensional space.

A basic 3-D plot is created with the plot3 command.

Plot3(x,y,z, ‘line specifiers’ , ‘PropertyName’ , property value)

x,y,z=Vector of the co-ordinates of the points.They must have the same number of elements

line specifiers=Optional;it defines the type and color of the line and markers

property value=Optional;it specifies the line width, and marker’s size and edge and fill colors

Page 20: POLYNOMIALS,CURVEFITTING, AND INTERPOLATION

For example, if the co-ordinates x,y,z are given as a function of the parameter t by:

x= √t sin(2t)y= √t cos (2t)z=0.5t

then a plot of the points for 0≤t≤6ᴫ can be produced as follows:

>> t=0:0.1:6*pi;>> x=sqrt(t).*sin(2*t);>> y=sqrt(t).*cos(2*t);>> z=0.5*;>> z=0.5*t;>> plot3(x,y,z,'k','linewidth',1)>> grid on>> xlabel('x');>> ylabel('y');>> zlabel('z');

Page 21: POLYNOMIALS,CURVEFITTING, AND INTERPOLATION
Page 22: POLYNOMIALS,CURVEFITTING, AND INTERPOLATION

MESH & SURFACE PLOTS:They are 3-Dimensional plots that are used for plotting

functions of the form z=f(x,y) where x and y are two independent variables and z is dependent variable.

Mesh & Surface plots are created in three steps:

*create a grid in the x-y plane*calculate the value of z at each point of the grid*create the plot

Page 23: POLYNOMIALS,CURVEFITTING, AND INTERPOLATION

# Making Mesh & Surface plots:

mesh (x,y,z) surf(x,y,z)

where x, y= Matrices with the co-ordinates of the gridz= A matrix with grid points

For example, try to make Mesh & Surface plot of the following function over -1≤x≤3 and 1≤y≤4:

Page 24: POLYNOMIALS,CURVEFITTING, AND INTERPOLATION

>> x=-1:0.1:3;>> y=1:0.1:4;>> [X,Y]=meshgrid(x,y);>> Z=X.*Y.^2./(X.^2+Y.^2);>> mesh(X,Y,Z)>> xlabel('x');>> ylabel('y');>> zlabel('z');