SlideShare a Scribd company logo
1 of 23
11
Polynomials and Curve Fitting
Lecture Series – 5
by
Shameer Koya
Polynomial
 Degree : 3
 For help abut polynomials in matlab, type help polyfun
2
Polynomials in MATLAB
 MATLAB provides a number of functions for the
manipulation of polynomials. These include,
 Evaluation of polynomials
 Finding roots of polynomials
 Addition, subtraction, multiplication, and division of polynomials
 Dealing with rational expressions of polynomials
 Curve fitting
Polynomials are defined in MATLAB as row vectors made up of the
coefficients of the polynomial, whose dimension is n+1, n being the
degree of the polynomial
p = [1 -12 0 25 116] represents x4 - 12x3 + 25x + 116
3
Roots
 >>p = [1, -12, 0, 25, 116]; % 4th order polynomial
>>r = roots(p)
r =
11.7473
2.7028
-1.2251 + 1.4672i
-1.2251 - 1.4672i
 From a set of roots we can also determine the polynomial
>>pp = poly(r)
r =
1 -12 -1.7764e-014 25 116
4
Addition and Subtraction
 MATLAB does not provide a direct function for adding or subtracting
polynomials unless they are of the same order, when they are of the
same order, normal matrix addition and subtraction applies, d = a + b
and e = a – b are defined when a and b are of the same order.
 When they are not of the same order, the lesser order polynomial must
be padded with leading zeroes before adding or subtracting the two
polynomials.
>>p1=[3 15 0 -10 -3 15 -40];
>>p2 = [3 0 -2 -6];
>>p = p1 + [0 0 0 p2];
>>p =
3 15 0 -7 -3 13 -46
The lesser polynomial is padded and then added or subtracted as
appropriate.
5
Multiplication
 Polynomial multiplication is supported by the conv function. For the
two polynomials
a(x) = x3 + 2x2 + 3x + 4
b(x) = x3 + 4x2 + 9x + 16
>>a = [1 2 3 4];
>>b = [1 4 9 16];
>>c = conv(a,b)
c =
1 6 20 50 75 84 64
or c(x) = x6 + 6x5 + 20x4 + 50x3 + 75x2 + 84x + 64
6
Multiplication II
 Couple observations,
 Multiplication of more than two polynomials requires repeated
use of the conv function.
 Polynomials need not be of the same order to use the conv
function.
 Remember that functions can be nested so conv(conv(a,b),c)
makes sense.
7
Division
 Division takes care of the case where we want to divide one polynomial
by another, in MATLAB we use the deconv function. In general
polynomial division yields a quotient polynomial and a remainder
polynomial. Let’s look at two cases;
 Case 1: suppose f(x)/g(x) has no remainder;
>>f=[2 9 7 -6];
>>g=[1 3];
>>[q,r] = deconv(f,g)
q =
2 3 -2 q(x) = 2x2 + 3x -2
r =
0 0 0 0 r(x) = 0
8
Division II
 The representation of r looks strange, but MATLAB outputs
r padding it with leading zeros so that length(r) = length of
f, or length(f).
 Case 2: now suppose f(x)/g(x) has a remainder,
>>f=[2 -13 0 75 2 0 -60];
>>g=[1 0 -5];
>>[q,r] = deconv(f,g)
q =
2 -13 10 10 52 q(x) = 2x4 - 13x3 + 10x2 + 10x + 52
r =
0 0 0 0 0 50 200 r(x) = -2x2 – 6x -12
9
Derivatives
 Derivative of
 Single polynomial
 k = polyder(p)
 Product of polynomials
 k = polyder(a,b)
 Quotient of two polynomials
 [n d] = polyder(u,v)
10
Evaluation
 MATLAB provides the function polyval to evaluate
polynomials. To use polyval you need to provide the
polynomial to evaluate and the range of values where the
polynomial is to be evaluated. Consider,
>>p = [1 4 -7 -10];
To evaluate p at x=5, use
>> polyval(p,5)
To evaluate for a set of values,
>>x = linspace(-1, 3, 100);
>>y = polyval(p,x);
>>plot(x,y)
>>title(‘Plot of x^3 + 4*x^2 – 7*x – 10’)
>>xlabel(‘x’)
11
Curve Fitting
 MATLAB provides a number of ways to fit a curve to a set of measured
data. One of these methods uses the “least squares” curve fit. This
technique minimizes the squared errors between the curve and the set
of measured data.
 The function polyfit solves the least squares polynomial curve fitting
problem.
 To use polyfit, we must supply the data and the order or degree of the
polynomial we wish to best fit to the data. For n = 1, the best fit straight
line is found, this is called linear regression. For n = 2 a quadratic
polynomial will be found.
12
Curve Fitting II
 Consider the following example; Suppose you take 11 measurements of
some physical system, each spaced 0.1 seconds apart from 0 to 1 sec.
Let x be the row vector specifying the time values, and y the row vector
of the actual measurements.
>>x = [0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1];
>>y = [-.447 1.978 3.28 6.16 7.08 7.34 7.66 9.56 9.48 9.30 11.2];
>>n = 2;
>>p = polyfit( x, y, n ) %Find the best quadratic fit to the data
p =
-9.8108 20.1293 -0.317
or p(x) = -9.8108x2 + 20.1293 – 0.317
13
Curve Fitting ....
 Let’s check out our least squares quadratic vs the
measurement data to see how well polyfit performed.
>>xi = linspace(0,1,100);
>>yi = polyval(p, xi);
>>plot(x,y,’-o’, xi, yi, ‘-’)
>>xlabel(‘x’), ylabel(‘y = f(x)’)
>>title(‘Second Order Curve Fitting Example’)
14
Curve Fitting ….
Circles are the data points, green line is the curve fit.
15
Polynomial fit (degree 2)
 Start with polynomial of degree 2 (i.e. quadratic):
p=polyfit(x,y,2)
p =
-0.0040 -0.0427 0.3152
 So the polynomial is -0.0040x2 - 0.0427x + 0.3152
 Could this be much use? Calculate the points using
polyval and then plot...
yi=polyval(p,xi);
plot(x,y,’d’,xi,yi)
16
Polynomial fit (degree 2)
17
Polynomial fit
 Degree 2 not much use, given we know it is cos function.
 If the data had come from elsewhere it would have to have a lot of
uncertainty (and we’d have to be very confident that the relationship
was parabolic) before we accepted this result.
 The order of polynomial relates to the number of turning
points (maxima and minima) that can be accommodated
 (for the quadratic case we would eventually come to a turning point, on
the left, not shown)
 For an nth order polynomial normally n-1 turning points
(sometimes less when maxima & minima coincide).
 Cosine wave extended to infinity has an infinity of turning
points.
 However can fit to our data but need at least 5th degree
polynomial as four turning points in range x = 0 to 10.
18
Polynomial fit (degree 5)
p=polyfit(x,y,5)
p =
0.0026 -0.0627 0.4931 -1.3452 0.4348 1.0098
 So a polynomial 0.0026x5 - 0.0627x4 + 0.4931x3 -1.3452x2
+ 0.4348x + 1.0098
yi=polyval(p,xi);
plot(x,y,’d’,xi,yi)
19
Polynomial fit (degree 5)
 Not bad. But can it be improved by increasing the polynomial order?
20
Polynomial fit (degree 8)
plot(x,y,'d',xi,yi,'b',xi,cos(xi),'r')
 agreement is now quite good (even better if we go to degree 9)
21
Summary of Polynomial Functions
22
Function Description
conv Multiply polynomials
deconv Divide polynomials
poly Polynomial with specified roots
polyder Polynomial derivative
polyfit Polynomial curve fitting
polyval Polynomial evaluation
polyvalm Matrix polynomial evaluation
residue Partial-fraction expansion (residues)
roots Find polynomial roots
23
Thanks
Questions ??

More Related Content

What's hot

Interpolation and its applications
Interpolation and its applicationsInterpolation and its applications
Interpolation and its applicationsRinkuMonani
 
Data Approximation in Mathematical Modelling Regression Analysis and Curve Fi...
Data Approximation in Mathematical Modelling Regression Analysis and Curve Fi...Data Approximation in Mathematical Modelling Regression Analysis and Curve Fi...
Data Approximation in Mathematical Modelling Regression Analysis and Curve Fi...Dr.Summiya Parveen
 
Numerical Analysis (Solution of Non-Linear Equations) part 2
Numerical Analysis (Solution of Non-Linear Equations) part 2Numerical Analysis (Solution of Non-Linear Equations) part 2
Numerical Analysis (Solution of Non-Linear Equations) part 2Asad Ali
 
A method for solving quadratic programming problems having linearly factoriz...
A method for solving quadratic programming problems having  linearly factoriz...A method for solving quadratic programming problems having  linearly factoriz...
A method for solving quadratic programming problems having linearly factoriz...IJMER
 
Langrange Interpolation Polynomials
Langrange Interpolation PolynomialsLangrange Interpolation Polynomials
Langrange Interpolation PolynomialsSohaib H. Khan
 
Jacobi iterative method
Jacobi iterative methodJacobi iterative method
Jacobi iterative methodLuckshay Batra
 
Newton’s Forward & backward interpolation
Newton’s Forward &  backward interpolation Newton’s Forward &  backward interpolation
Newton’s Forward & backward interpolation Meet Patel
 
Group homomorphism
Group homomorphismGroup homomorphism
Group homomorphismNaliniSPatil
 
Least square method
Least square methodLeast square method
Least square methodSomya Bagai
 
Application of interpolation and finite difference
Application of interpolation and finite differenceApplication of interpolation and finite difference
Application of interpolation and finite differenceManthan Chavda
 
Convex Optimization
Convex OptimizationConvex Optimization
Convex Optimizationadil raja
 
Cauchy riemann equations
Cauchy riemann equationsCauchy riemann equations
Cauchy riemann equationssajidpk92
 
Newton divided difference interpolation
Newton divided difference interpolationNewton divided difference interpolation
Newton divided difference interpolationVISHAL DONGA
 

What's hot (20)

Interpolation and its applications
Interpolation and its applicationsInterpolation and its applications
Interpolation and its applications
 
newton raphson method
newton raphson methodnewton raphson method
newton raphson method
 
Data Approximation in Mathematical Modelling Regression Analysis and Curve Fi...
Data Approximation in Mathematical Modelling Regression Analysis and Curve Fi...Data Approximation in Mathematical Modelling Regression Analysis and Curve Fi...
Data Approximation in Mathematical Modelling Regression Analysis and Curve Fi...
 
Numerical Analysis (Solution of Non-Linear Equations) part 2
Numerical Analysis (Solution of Non-Linear Equations) part 2Numerical Analysis (Solution of Non-Linear Equations) part 2
Numerical Analysis (Solution of Non-Linear Equations) part 2
 
A method for solving quadratic programming problems having linearly factoriz...
A method for solving quadratic programming problems having  linearly factoriz...A method for solving quadratic programming problems having  linearly factoriz...
A method for solving quadratic programming problems having linearly factoriz...
 
Langrange Interpolation Polynomials
Langrange Interpolation PolynomialsLangrange Interpolation Polynomials
Langrange Interpolation Polynomials
 
Jacobi iterative method
Jacobi iterative methodJacobi iterative method
Jacobi iterative method
 
Interpolation
InterpolationInterpolation
Interpolation
 
Newton’s Forward & backward interpolation
Newton’s Forward &  backward interpolation Newton’s Forward &  backward interpolation
Newton’s Forward & backward interpolation
 
Taylors series
Taylors series Taylors series
Taylors series
 
GAUSS ELIMINATION METHOD
 GAUSS ELIMINATION METHOD GAUSS ELIMINATION METHOD
GAUSS ELIMINATION METHOD
 
Group homomorphism
Group homomorphismGroup homomorphism
Group homomorphism
 
Ridge regression
Ridge regressionRidge regression
Ridge regression
 
Least square method
Least square methodLeast square method
Least square method
 
Application of interpolation and finite difference
Application of interpolation and finite differenceApplication of interpolation and finite difference
Application of interpolation and finite difference
 
Convex Optimization
Convex OptimizationConvex Optimization
Convex Optimization
 
Romberg’s method
Romberg’s methodRomberg’s method
Romberg’s method
 
Cauchy riemann equations
Cauchy riemann equationsCauchy riemann equations
Cauchy riemann equations
 
FPDE presentation
FPDE presentationFPDE presentation
FPDE presentation
 
Newton divided difference interpolation
Newton divided difference interpolationNewton divided difference interpolation
Newton divided difference interpolation
 

Viewers also liked

Curve fitting - Lecture Notes
Curve fitting - Lecture NotesCurve fitting - Lecture Notes
Curve fitting - Lecture NotesDr. Nirav Vyas
 
Curve Fitting results 1110
Curve Fitting results 1110Curve Fitting results 1110
Curve Fitting results 1110Ray Wang
 
Applocation of Numerical Methods
Applocation of Numerical MethodsApplocation of Numerical Methods
Applocation of Numerical MethodsNahian Ahmed
 
The least square method
The least square methodThe least square method
The least square methodkevinlefol
 
Applied numerical methods lec8
Applied numerical methods lec8Applied numerical methods lec8
Applied numerical methods lec8Yasser Ahmed
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introductionAmeen San
 
Matlab m files and scripts
Matlab m files and scriptsMatlab m files and scripts
Matlab m files and scriptsAmeen San
 
Matlab matrices and arrays
Matlab matrices and arraysMatlab matrices and arrays
Matlab matrices and arraysAmeen San
 
Matlab ploting
Matlab plotingMatlab ploting
Matlab plotingAmeen San
 
case study of curve fitting
case study of curve fittingcase study of curve fitting
case study of curve fittingAdarsh Patel
 
Matlab complex numbers
Matlab complex numbersMatlab complex numbers
Matlab complex numbersAmeen San
 
Microprocessor and Microcontroller lec4
Microprocessor and Microcontroller lec4Microprocessor and Microcontroller lec4
Microprocessor and Microcontroller lec4Ameen San
 
Matlab dc circuit analysis
Matlab dc circuit analysisMatlab dc circuit analysis
Matlab dc circuit analysisAmeen San
 
Basic concepts of curve fittings
Basic concepts of curve fittingsBasic concepts of curve fittings
Basic concepts of curve fittingsTarun Gehlot
 
Microprocessor and Microcontroller lec5
Microprocessor and Microcontroller lec5Microprocessor and Microcontroller lec5
Microprocessor and Microcontroller lec5Ameen San
 
Spline Interpolation
Spline InterpolationSpline Interpolation
Spline InterpolationaiQUANT
 
Plc analog input output programming
Plc analog input output programmingPlc analog input output programming
Plc analog input output programmingEngr Alam
 

Viewers also liked (20)

Curve fitting
Curve fittingCurve fitting
Curve fitting
 
Curve fitting - Lecture Notes
Curve fitting - Lecture NotesCurve fitting - Lecture Notes
Curve fitting - Lecture Notes
 
Curve Fitting results 1110
Curve Fitting results 1110Curve Fitting results 1110
Curve Fitting results 1110
 
Applocation of Numerical Methods
Applocation of Numerical MethodsApplocation of Numerical Methods
Applocation of Numerical Methods
 
151028_abajpai1
151028_abajpai1151028_abajpai1
151028_abajpai1
 
The least square method
The least square methodThe least square method
The least square method
 
Applied numerical methods lec8
Applied numerical methods lec8Applied numerical methods lec8
Applied numerical methods lec8
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
 
Matlab m files and scripts
Matlab m files and scriptsMatlab m files and scripts
Matlab m files and scripts
 
Matlab matrices and arrays
Matlab matrices and arraysMatlab matrices and arrays
Matlab matrices and arrays
 
Matlab ploting
Matlab plotingMatlab ploting
Matlab ploting
 
case study of curve fitting
case study of curve fittingcase study of curve fitting
case study of curve fitting
 
Matlab complex numbers
Matlab complex numbersMatlab complex numbers
Matlab complex numbers
 
Introto pl cs
Introto pl csIntroto pl cs
Introto pl cs
 
Microprocessor and Microcontroller lec4
Microprocessor and Microcontroller lec4Microprocessor and Microcontroller lec4
Microprocessor and Microcontroller lec4
 
Matlab dc circuit analysis
Matlab dc circuit analysisMatlab dc circuit analysis
Matlab dc circuit analysis
 
Basic concepts of curve fittings
Basic concepts of curve fittingsBasic concepts of curve fittings
Basic concepts of curve fittings
 
Microprocessor and Microcontroller lec5
Microprocessor and Microcontroller lec5Microprocessor and Microcontroller lec5
Microprocessor and Microcontroller lec5
 
Spline Interpolation
Spline InterpolationSpline Interpolation
Spline Interpolation
 
Plc analog input output programming
Plc analog input output programmingPlc analog input output programming
Plc analog input output programming
 

Similar to Matlab polynimials and curve fitting

Advanced matlab codigos matematicos
Advanced matlab codigos matematicosAdvanced matlab codigos matematicos
Advanced matlab codigos matematicosKmilo Bolaños
 
STA003_WK4_L.pptx
STA003_WK4_L.pptxSTA003_WK4_L.pptx
STA003_WK4_L.pptxMAmir23
 
Appendex b
Appendex bAppendex b
Appendex bswavicky
 
curve fitting or regression analysis-1.pptx
curve fitting or regression analysis-1.pptxcurve fitting or regression analysis-1.pptx
curve fitting or regression analysis-1.pptxabelmeketa
 
Module 3 polynomial functions
Module 3   polynomial functionsModule 3   polynomial functions
Module 3 polynomial functionsdionesioable
 
Lagrange Interpolation
Lagrange InterpolationLagrange Interpolation
Lagrange InterpolationSaloni Singhal
 
8.further calculus Further Mathematics Zimbabwe Zimsec Cambridge
8.further calculus   Further Mathematics Zimbabwe Zimsec Cambridge8.further calculus   Further Mathematics Zimbabwe Zimsec Cambridge
8.further calculus Further Mathematics Zimbabwe Zimsec Cambridgealproelearning
 
Calculus - Functions Review
Calculus - Functions ReviewCalculus - Functions Review
Calculus - Functions Reviewhassaanciit
 
Rosser's theorem
Rosser's theoremRosser's theorem
Rosser's theoremWathna
 
Recursive Definitions in Discrete Mathmatcs.pptx
Recursive Definitions in Discrete Mathmatcs.pptxRecursive Definitions in Discrete Mathmatcs.pptx
Recursive Definitions in Discrete Mathmatcs.pptxgbikorno
 
The remainder theorem powerpoint
The remainder theorem powerpointThe remainder theorem powerpoint
The remainder theorem powerpointJuwileene Soriano
 
Synthetic and Remainder Theorem of Polynomials.ppt
Synthetic and Remainder Theorem of Polynomials.pptSynthetic and Remainder Theorem of Polynomials.ppt
Synthetic and Remainder Theorem of Polynomials.pptMarkVincentDoria1
 

Similar to Matlab polynimials and curve fitting (20)

Advanced matlab codigos matematicos
Advanced matlab codigos matematicosAdvanced matlab codigos matematicos
Advanced matlab codigos matematicos
 
3_MLE_printable.pdf
3_MLE_printable.pdf3_MLE_printable.pdf
3_MLE_printable.pdf
 
STA003_WK4_L.pptx
STA003_WK4_L.pptxSTA003_WK4_L.pptx
STA003_WK4_L.pptx
 
5 numerical analysis
5 numerical analysis5 numerical analysis
5 numerical analysis
 
Appendex b
Appendex bAppendex b
Appendex b
 
curve fitting or regression analysis-1.pptx
curve fitting or regression analysis-1.pptxcurve fitting or regression analysis-1.pptx
curve fitting or regression analysis-1.pptx
 
Regression
RegressionRegression
Regression
 
Module 3 polynomial functions
Module 3   polynomial functionsModule 3   polynomial functions
Module 3 polynomial functions
 
CALCULUS 2.pptx
CALCULUS 2.pptxCALCULUS 2.pptx
CALCULUS 2.pptx
 
Lagrange Interpolation
Lagrange InterpolationLagrange Interpolation
Lagrange Interpolation
 
Numerical methods generating polynomial
Numerical methods generating polynomialNumerical methods generating polynomial
Numerical methods generating polynomial
 
8.further calculus Further Mathematics Zimbabwe Zimsec Cambridge
8.further calculus   Further Mathematics Zimbabwe Zimsec Cambridge8.further calculus   Further Mathematics Zimbabwe Zimsec Cambridge
8.further calculus Further Mathematics Zimbabwe Zimsec Cambridge
 
Karnaugh
KarnaughKarnaugh
Karnaugh
 
Calculus - Functions Review
Calculus - Functions ReviewCalculus - Functions Review
Calculus - Functions Review
 
Rosser's theorem
Rosser's theoremRosser's theorem
Rosser's theorem
 
Finding values of polynomial functions
Finding values of polynomial functionsFinding values of polynomial functions
Finding values of polynomial functions
 
Recursive Definitions in Discrete Mathmatcs.pptx
Recursive Definitions in Discrete Mathmatcs.pptxRecursive Definitions in Discrete Mathmatcs.pptx
Recursive Definitions in Discrete Mathmatcs.pptx
 
Signals and Systems Homework Help.pptx
Signals and Systems Homework Help.pptxSignals and Systems Homework Help.pptx
Signals and Systems Homework Help.pptx
 
The remainder theorem powerpoint
The remainder theorem powerpointThe remainder theorem powerpoint
The remainder theorem powerpoint
 
Synthetic and Remainder Theorem of Polynomials.ppt
Synthetic and Remainder Theorem of Polynomials.pptSynthetic and Remainder Theorem of Polynomials.ppt
Synthetic and Remainder Theorem of Polynomials.ppt
 

More from Ameen San

Application of Capacitors to Distribution System and Voltage Regulation
Application of Capacitors to Distribution System and Voltage RegulationApplication of Capacitors to Distribution System and Voltage Regulation
Application of Capacitors to Distribution System and Voltage RegulationAmeen San
 
Distribution System Voltage Drop and Power Loss Calculation
Distribution System Voltage Drop and Power Loss CalculationDistribution System Voltage Drop and Power Loss Calculation
Distribution System Voltage Drop and Power Loss CalculationAmeen San
 
Load Characteristics
Load CharacteristicsLoad Characteristics
Load CharacteristicsAmeen San
 
ELECTRICAL DISTRIBUTION TECHNOLOGY
ELECTRICAL DISTRIBUTION TECHNOLOGYELECTRICAL DISTRIBUTION TECHNOLOGY
ELECTRICAL DISTRIBUTION TECHNOLOGYAmeen San
 
Stepper motor
Stepper motor Stepper motor
Stepper motor Ameen San
 
PLC application
PLC applicationPLC application
PLC applicationAmeen San
 
PLC arithmatic functions
PLC arithmatic functionsPLC arithmatic functions
PLC arithmatic functionsAmeen San
 
PLC data types and addressing
PLC data types and addressingPLC data types and addressing
PLC data types and addressingAmeen San
 
PLC Counters
PLC CountersPLC Counters
PLC CountersAmeen San
 
PLC Traffic Light Control
PLC Traffic Light ControlPLC Traffic Light Control
PLC Traffic Light ControlAmeen San
 
PLC Internal Relays
PLC Internal RelaysPLC Internal Relays
PLC Internal RelaysAmeen San
 
PLC Intro to programming
PLC Intro to programmingPLC Intro to programming
PLC Intro to programmingAmeen San
 
PLC Logic Circuits
PLC Logic CircuitsPLC Logic Circuits
PLC Logic CircuitsAmeen San
 
PLC input and output devices
PLC input and output devices PLC input and output devices
PLC input and output devices Ameen San
 
PLC Applications
PLC ApplicationsPLC Applications
PLC ApplicationsAmeen San
 
Protection Devices and the Lightning
Protection Devices and the LightningProtection Devices and the Lightning
Protection Devices and the LightningAmeen San
 
Circuit Breakers
Circuit BreakersCircuit Breakers
Circuit BreakersAmeen San
 

More from Ameen San (20)

Application of Capacitors to Distribution System and Voltage Regulation
Application of Capacitors to Distribution System and Voltage RegulationApplication of Capacitors to Distribution System and Voltage Regulation
Application of Capacitors to Distribution System and Voltage Regulation
 
Distribution System Voltage Drop and Power Loss Calculation
Distribution System Voltage Drop and Power Loss CalculationDistribution System Voltage Drop and Power Loss Calculation
Distribution System Voltage Drop and Power Loss Calculation
 
Load Characteristics
Load CharacteristicsLoad Characteristics
Load Characteristics
 
ELECTRICAL DISTRIBUTION TECHNOLOGY
ELECTRICAL DISTRIBUTION TECHNOLOGYELECTRICAL DISTRIBUTION TECHNOLOGY
ELECTRICAL DISTRIBUTION TECHNOLOGY
 
Stepper motor
Stepper motor Stepper motor
Stepper motor
 
PLC application
PLC applicationPLC application
PLC application
 
PLC arithmatic functions
PLC arithmatic functionsPLC arithmatic functions
PLC arithmatic functions
 
PLC data types and addressing
PLC data types and addressingPLC data types and addressing
PLC data types and addressing
 
PLC Counters
PLC CountersPLC Counters
PLC Counters
 
PLC Traffic Light Control
PLC Traffic Light ControlPLC Traffic Light Control
PLC Traffic Light Control
 
PLC Timers
PLC TimersPLC Timers
PLC Timers
 
PLC Internal Relays
PLC Internal RelaysPLC Internal Relays
PLC Internal Relays
 
PLC Intro to programming
PLC Intro to programmingPLC Intro to programming
PLC Intro to programming
 
PLC Logic Circuits
PLC Logic CircuitsPLC Logic Circuits
PLC Logic Circuits
 
PLC input and output devices
PLC input and output devices PLC input and output devices
PLC input and output devices
 
PLC Applications
PLC ApplicationsPLC Applications
PLC Applications
 
Protection Devices and the Lightning
Protection Devices and the LightningProtection Devices and the Lightning
Protection Devices and the Lightning
 
Protection
ProtectionProtection
Protection
 
Relays
RelaysRelays
Relays
 
Circuit Breakers
Circuit BreakersCircuit Breakers
Circuit Breakers
 

Recently uploaded

Basic Electronics for diploma students as per technical education Kerala Syll...
Basic Electronics for diploma students as per technical education Kerala Syll...Basic Electronics for diploma students as per technical education Kerala Syll...
Basic Electronics for diploma students as per technical education Kerala Syll...ppkakm
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueBhangaleSonal
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...Amil baba
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network DevicesChandrakantDivate1
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
Introduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdfIntroduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdfsumitt6_25730773
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesMayuraD1
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdfKamal Acharya
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationBhangaleSonal
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...jabtakhaidam7
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdfKamal Acharya
 
Computer Graphics Introduction To Curves
Computer Graphics Introduction To CurvesComputer Graphics Introduction To Curves
Computer Graphics Introduction To CurvesChandrakantDivate1
 
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...ronahami
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Arindam Chakraborty, Ph.D., P.E. (CA, TX)
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...drmkjayanthikannan
 
Ghuma $ Russian Call Girls Ahmedabad ₹7.5k Pick Up & Drop With Cash Payment 8...
Ghuma $ Russian Call Girls Ahmedabad ₹7.5k Pick Up & Drop With Cash Payment 8...Ghuma $ Russian Call Girls Ahmedabad ₹7.5k Pick Up & Drop With Cash Payment 8...
Ghuma $ Russian Call Girls Ahmedabad ₹7.5k Pick Up & Drop With Cash Payment 8...gragchanchal546
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Servicemeghakumariji156
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayEpec Engineered Technologies
 

Recently uploaded (20)

Basic Electronics for diploma students as per technical education Kerala Syll...
Basic Electronics for diploma students as per technical education Kerala Syll...Basic Electronics for diploma students as per technical education Kerala Syll...
Basic Electronics for diploma students as per technical education Kerala Syll...
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Introduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdfIntroduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdf
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
Computer Graphics Introduction To Curves
Computer Graphics Introduction To CurvesComputer Graphics Introduction To Curves
Computer Graphics Introduction To Curves
 
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 
Ghuma $ Russian Call Girls Ahmedabad ₹7.5k Pick Up & Drop With Cash Payment 8...
Ghuma $ Russian Call Girls Ahmedabad ₹7.5k Pick Up & Drop With Cash Payment 8...Ghuma $ Russian Call Girls Ahmedabad ₹7.5k Pick Up & Drop With Cash Payment 8...
Ghuma $ Russian Call Girls Ahmedabad ₹7.5k Pick Up & Drop With Cash Payment 8...
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 

Matlab polynimials and curve fitting

  • 1. 11 Polynomials and Curve Fitting Lecture Series – 5 by Shameer Koya
  • 2. Polynomial  Degree : 3  For help abut polynomials in matlab, type help polyfun 2
  • 3. Polynomials in MATLAB  MATLAB provides a number of functions for the manipulation of polynomials. These include,  Evaluation of polynomials  Finding roots of polynomials  Addition, subtraction, multiplication, and division of polynomials  Dealing with rational expressions of polynomials  Curve fitting Polynomials are defined in MATLAB as row vectors made up of the coefficients of the polynomial, whose dimension is n+1, n being the degree of the polynomial p = [1 -12 0 25 116] represents x4 - 12x3 + 25x + 116 3
  • 4. Roots  >>p = [1, -12, 0, 25, 116]; % 4th order polynomial >>r = roots(p) r = 11.7473 2.7028 -1.2251 + 1.4672i -1.2251 - 1.4672i  From a set of roots we can also determine the polynomial >>pp = poly(r) r = 1 -12 -1.7764e-014 25 116 4
  • 5. Addition and Subtraction  MATLAB does not provide a direct function for adding or subtracting polynomials unless they are of the same order, when they are of the same order, normal matrix addition and subtraction applies, d = a + b and e = a – b are defined when a and b are of the same order.  When they are not of the same order, the lesser order polynomial must be padded with leading zeroes before adding or subtracting the two polynomials. >>p1=[3 15 0 -10 -3 15 -40]; >>p2 = [3 0 -2 -6]; >>p = p1 + [0 0 0 p2]; >>p = 3 15 0 -7 -3 13 -46 The lesser polynomial is padded and then added or subtracted as appropriate. 5
  • 6. Multiplication  Polynomial multiplication is supported by the conv function. For the two polynomials a(x) = x3 + 2x2 + 3x + 4 b(x) = x3 + 4x2 + 9x + 16 >>a = [1 2 3 4]; >>b = [1 4 9 16]; >>c = conv(a,b) c = 1 6 20 50 75 84 64 or c(x) = x6 + 6x5 + 20x4 + 50x3 + 75x2 + 84x + 64 6
  • 7. Multiplication II  Couple observations,  Multiplication of more than two polynomials requires repeated use of the conv function.  Polynomials need not be of the same order to use the conv function.  Remember that functions can be nested so conv(conv(a,b),c) makes sense. 7
  • 8. Division  Division takes care of the case where we want to divide one polynomial by another, in MATLAB we use the deconv function. In general polynomial division yields a quotient polynomial and a remainder polynomial. Let’s look at two cases;  Case 1: suppose f(x)/g(x) has no remainder; >>f=[2 9 7 -6]; >>g=[1 3]; >>[q,r] = deconv(f,g) q = 2 3 -2 q(x) = 2x2 + 3x -2 r = 0 0 0 0 r(x) = 0 8
  • 9. Division II  The representation of r looks strange, but MATLAB outputs r padding it with leading zeros so that length(r) = length of f, or length(f).  Case 2: now suppose f(x)/g(x) has a remainder, >>f=[2 -13 0 75 2 0 -60]; >>g=[1 0 -5]; >>[q,r] = deconv(f,g) q = 2 -13 10 10 52 q(x) = 2x4 - 13x3 + 10x2 + 10x + 52 r = 0 0 0 0 0 50 200 r(x) = -2x2 – 6x -12 9
  • 10. Derivatives  Derivative of  Single polynomial  k = polyder(p)  Product of polynomials  k = polyder(a,b)  Quotient of two polynomials  [n d] = polyder(u,v) 10
  • 11. Evaluation  MATLAB provides the function polyval to evaluate polynomials. To use polyval you need to provide the polynomial to evaluate and the range of values where the polynomial is to be evaluated. Consider, >>p = [1 4 -7 -10]; To evaluate p at x=5, use >> polyval(p,5) To evaluate for a set of values, >>x = linspace(-1, 3, 100); >>y = polyval(p,x); >>plot(x,y) >>title(‘Plot of x^3 + 4*x^2 – 7*x – 10’) >>xlabel(‘x’) 11
  • 12. Curve Fitting  MATLAB provides a number of ways to fit a curve to a set of measured data. One of these methods uses the “least squares” curve fit. This technique minimizes the squared errors between the curve and the set of measured data.  The function polyfit solves the least squares polynomial curve fitting problem.  To use polyfit, we must supply the data and the order or degree of the polynomial we wish to best fit to the data. For n = 1, the best fit straight line is found, this is called linear regression. For n = 2 a quadratic polynomial will be found. 12
  • 13. Curve Fitting II  Consider the following example; Suppose you take 11 measurements of some physical system, each spaced 0.1 seconds apart from 0 to 1 sec. Let x be the row vector specifying the time values, and y the row vector of the actual measurements. >>x = [0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1]; >>y = [-.447 1.978 3.28 6.16 7.08 7.34 7.66 9.56 9.48 9.30 11.2]; >>n = 2; >>p = polyfit( x, y, n ) %Find the best quadratic fit to the data p = -9.8108 20.1293 -0.317 or p(x) = -9.8108x2 + 20.1293 – 0.317 13
  • 14. Curve Fitting ....  Let’s check out our least squares quadratic vs the measurement data to see how well polyfit performed. >>xi = linspace(0,1,100); >>yi = polyval(p, xi); >>plot(x,y,’-o’, xi, yi, ‘-’) >>xlabel(‘x’), ylabel(‘y = f(x)’) >>title(‘Second Order Curve Fitting Example’) 14
  • 15. Curve Fitting …. Circles are the data points, green line is the curve fit. 15
  • 16. Polynomial fit (degree 2)  Start with polynomial of degree 2 (i.e. quadratic): p=polyfit(x,y,2) p = -0.0040 -0.0427 0.3152  So the polynomial is -0.0040x2 - 0.0427x + 0.3152  Could this be much use? Calculate the points using polyval and then plot... yi=polyval(p,xi); plot(x,y,’d’,xi,yi) 16
  • 18. Polynomial fit  Degree 2 not much use, given we know it is cos function.  If the data had come from elsewhere it would have to have a lot of uncertainty (and we’d have to be very confident that the relationship was parabolic) before we accepted this result.  The order of polynomial relates to the number of turning points (maxima and minima) that can be accommodated  (for the quadratic case we would eventually come to a turning point, on the left, not shown)  For an nth order polynomial normally n-1 turning points (sometimes less when maxima & minima coincide).  Cosine wave extended to infinity has an infinity of turning points.  However can fit to our data but need at least 5th degree polynomial as four turning points in range x = 0 to 10. 18
  • 19. Polynomial fit (degree 5) p=polyfit(x,y,5) p = 0.0026 -0.0627 0.4931 -1.3452 0.4348 1.0098  So a polynomial 0.0026x5 - 0.0627x4 + 0.4931x3 -1.3452x2 + 0.4348x + 1.0098 yi=polyval(p,xi); plot(x,y,’d’,xi,yi) 19
  • 20. Polynomial fit (degree 5)  Not bad. But can it be improved by increasing the polynomial order? 20
  • 21. Polynomial fit (degree 8) plot(x,y,'d',xi,yi,'b',xi,cos(xi),'r')  agreement is now quite good (even better if we go to degree 9) 21
  • 22. Summary of Polynomial Functions 22 Function Description conv Multiply polynomials deconv Divide polynomials poly Polynomial with specified roots polyder Polynomial derivative polyfit Polynomial curve fitting polyval Polynomial evaluation polyvalm Matrix polynomial evaluation residue Partial-fraction expansion (residues) roots Find polynomial roots