SlideShare a Scribd company logo
1 of 2
Download to read offline
http://www.tutorialspoint.com/matlab/matlab_polynomials.htm Copyright © tutorialspoint.com
MATLAB - POLYNOMIALS
MATLAB represents polynomials as row vectors containing coefficients ordered by descending powers. For
example, the equationP(x) = x4 + 7x3 - 5x + 9 could be represented as:
p = [1 7 0 -5 9];
Evaluating Polynomials
The polyval functionis used for evaluating a polynomialat a specified value. For example, to evaluate our
previous polynomialp, at x = 4, type:
p = [1 7 0 -5 9];
polyval(p,4)
MATLAB executes the above statements and returns the following result:
ans =
693
MATLAB also provides the polyvalmfunctionfor evaluating a matrix polynomial. A matrix polynomialis a
polynomial withmatrices as variables.
For example, let us create a square matrix X and evaluate the polynomialp, at X:
p = [1 7 0 -5 9];
X = [1 2 -3 4; 2 -5 6 3; 3 1 0 2; 5 -7 3 8];
polyvalm(p, X)
MATLAB executes the above statements and returns the following result:
ans =
2307 -1769 -939 4499
2314 -2376 -249 4695
2256 -1892 -549 4310
4570 -4532 -1062 9269
Finding the Roots of Polynomials
The roots functioncalculates the roots of a polynomial. For example, to calculate the roots of our polynomialp,
type:
p = [1 7 0 -5 9];
r = roots(p)
MATLAB executes the above statements and returns the following result:
r =
-6.8661 + 0.0000i
-1.4247 + 0.0000i
0.6454 + 0.7095i
0.6454 - 0.7095i
The functionpoly is aninverse of the roots functionand returns to the polynomialcoefficients. For example:
p2 = poly(r)
MATLAB executes the above statements and returns the following result:
p2 =
1.0000 7.0000 0.0000 -5.0000 9.0000
Polynomial Curve Fitting
The polyfit functionfinds the coefficients of a polynomialthat fits a set of data ina least-squares sense. If x and y
are two vectors containing the x and y data to be fitted to a n-degree polynomial, thenwe get the polynomial
fitting the data by writing:
p = polyfit(x,y,n)
Example
Create a script file and type the following code:
x = [1 2 3 4 5 6]; y = [5.5 43.1 128 290.7 498.4 978.67]; %data
p = polyfit(x,y,4) %get the polynomial
% Compute the values of the polyfit estimate over a finer range,
% and plot the estimate over the real data values for comparison:
x2 = 1:.1:6;
y2 = polyval(p,x2);
plot(x,y,'o',x2,y2)
grid on
Whenyourunthe file, MATLAB displays the following result:
p =
4.1056 -47.9607 222.2598 -362.7453 191.1250
And plots the following graph:

More Related Content

What's hot

Arrays and Pointers
Arrays and PointersArrays and Pointers
Arrays and PointersSimoniShah6
 
Python - Numpy/Pandas/Matplot Machine Learning Libraries
Python - Numpy/Pandas/Matplot Machine Learning LibrariesPython - Numpy/Pandas/Matplot Machine Learning Libraries
Python - Numpy/Pandas/Matplot Machine Learning LibrariesAndrew Ferlitsch
 
Intoduction to numpy
Intoduction to numpyIntoduction to numpy
Intoduction to numpyFaraz Ahmed
 
Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)PyData
 
Map filter reduce in Python
Map filter reduce in PythonMap filter reduce in Python
Map filter reduce in PythonAdnan Siddiqi
 
statistical computation using R- an intro..
statistical computation using R- an intro..statistical computation using R- an intro..
statistical computation using R- an intro..Kamarudheen KV
 
Introduction to TensorFlow, by Machine Learning at Berkeley
Introduction to TensorFlow, by Machine Learning at BerkeleyIntroduction to TensorFlow, by Machine Learning at Berkeley
Introduction to TensorFlow, by Machine Learning at BerkeleyTed Xiao
 
Scala. Introduction to FP. Monads
Scala. Introduction to FP. MonadsScala. Introduction to FP. Monads
Scala. Introduction to FP. MonadsKirill Kozlov
 
Extending built in objects
Extending built in objectsExtending built in objects
Extending built in objectsMuhammad Ahmed
 
Introduction to numpy Session 1
Introduction to numpy Session 1Introduction to numpy Session 1
Introduction to numpy Session 1Jatin Miglani
 

What's hot (18)

Arrays and Pointers
Arrays and PointersArrays and Pointers
Arrays and Pointers
 
Numpy
NumpyNumpy
Numpy
 
Python - Numpy/Pandas/Matplot Machine Learning Libraries
Python - Numpy/Pandas/Matplot Machine Learning LibrariesPython - Numpy/Pandas/Matplot Machine Learning Libraries
Python - Numpy/Pandas/Matplot Machine Learning Libraries
 
NumPy
NumPyNumPy
NumPy
 
Pointers
PointersPointers
Pointers
 
Matlab integration
Matlab integrationMatlab integration
Matlab integration
 
Intoduction to numpy
Intoduction to numpyIntoduction to numpy
Intoduction to numpy
 
Pointers
PointersPointers
Pointers
 
Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)
 
Map filter reduce in Python
Map filter reduce in PythonMap filter reduce in Python
Map filter reduce in Python
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
A02
A02A02
A02
 
statistical computation using R- an intro..
statistical computation using R- an intro..statistical computation using R- an intro..
statistical computation using R- an intro..
 
Introduction to numpy
Introduction to numpyIntroduction to numpy
Introduction to numpy
 
Introduction to TensorFlow, by Machine Learning at Berkeley
Introduction to TensorFlow, by Machine Learning at BerkeleyIntroduction to TensorFlow, by Machine Learning at Berkeley
Introduction to TensorFlow, by Machine Learning at Berkeley
 
Scala. Introduction to FP. Monads
Scala. Introduction to FP. MonadsScala. Introduction to FP. Monads
Scala. Introduction to FP. Monads
 
Extending built in objects
Extending built in objectsExtending built in objects
Extending built in objects
 
Introduction to numpy Session 1
Introduction to numpy Session 1Introduction to numpy Session 1
Introduction to numpy Session 1
 

Viewers also liked

Inundacions Octubre 1930
Inundacions Octubre 1930Inundacions Octubre 1930
Inundacions Octubre 1930gamameteo
 
El trabajo de dos alumnos
El trabajo de dos alumnosEl trabajo de dos alumnos
El trabajo de dos alumnosAlex Rosales
 
Gabrielrojas gobierno en linea
Gabrielrojas gobierno en lineaGabrielrojas gobierno en linea
Gabrielrojas gobierno en lineagabrielrojas09
 
Propuesta para Referentes
Propuesta para ReferentesPropuesta para Referentes
Propuesta para ReferentesDiego Capurro
 
Government Procurement Benefits of Green Proposals Services
Government Procurement Benefits of Green Proposals ServicesGovernment Procurement Benefits of Green Proposals Services
Government Procurement Benefits of Green Proposals ServicesGreen Proposals
 
Witte mars
Witte marsWitte mars
Witte marsr0442221
 

Viewers also liked (12)

Inundacions Octubre 1930
Inundacions Octubre 1930Inundacions Octubre 1930
Inundacions Octubre 1930
 
Genetics 2008
Genetics 2008Genetics 2008
Genetics 2008
 
El trabajo de dos alumnos
El trabajo de dos alumnosEl trabajo de dos alumnos
El trabajo de dos alumnos
 
APPLICATION FOR PARTNERSHIP OR SUPPORT FOR SPORTS
APPLICATION FOR PARTNERSHIP OR SUPPORT FOR SPORTSAPPLICATION FOR PARTNERSHIP OR SUPPORT FOR SPORTS
APPLICATION FOR PARTNERSHIP OR SUPPORT FOR SPORTS
 
Gabrielrojas gobierno en linea
Gabrielrojas gobierno en lineaGabrielrojas gobierno en linea
Gabrielrojas gobierno en linea
 
Propuesta para Referentes
Propuesta para ReferentesPropuesta para Referentes
Propuesta para Referentes
 
Government Procurement Benefits of Green Proposals Services
Government Procurement Benefits of Green Proposals ServicesGovernment Procurement Benefits of Green Proposals Services
Government Procurement Benefits of Green Proposals Services
 
Edilsa palacios actividad1_mapa_cpdf.jpg
Edilsa palacios actividad1_mapa_cpdf.jpgEdilsa palacios actividad1_mapa_cpdf.jpg
Edilsa palacios actividad1_mapa_cpdf.jpg
 
K igama
K igamaK igama
K igama
 
Matlab loops
Matlab loopsMatlab loops
Matlab loops
 
Witte mars
Witte marsWitte mars
Witte mars
 
Matlab operators
Matlab operatorsMatlab operators
Matlab operators
 

Similar to Matlab polynomials

Similar to Matlab polynomials (20)

Lecture three
Lecture threeLecture three
Lecture three
 
Matlab polynimials and curve fitting
Matlab polynimials and curve fittingMatlab polynimials and curve fitting
Matlab polynimials and curve fitting
 
Advanced matlab codigos matematicos
Advanced matlab codigos matematicosAdvanced matlab codigos matematicos
Advanced matlab codigos matematicos
 
Polynomials and Curve Fitting in MATLAB
Polynomials and Curve Fitting in MATLABPolynomials and Curve Fitting in MATLAB
Polynomials and Curve Fitting in MATLAB
 
Matlab variables
Matlab variablesMatlab variables
Matlab variables
 
Lecture 3 - Introduction to Interpolation
Lecture 3 - Introduction to InterpolationLecture 3 - Introduction to Interpolation
Lecture 3 - Introduction to Interpolation
 
maXbox starter69 Machine Learning VII
maXbox starter69 Machine Learning VIImaXbox starter69 Machine Learning VII
maXbox starter69 Machine Learning VII
 
NUMPY [Autosaved] .pptx
NUMPY [Autosaved]                    .pptxNUMPY [Autosaved]                    .pptx
NUMPY [Autosaved] .pptx
 
3_MLE_printable.pdf
3_MLE_printable.pdf3_MLE_printable.pdf
3_MLE_printable.pdf
 
Matlab algebra
Matlab algebraMatlab algebra
Matlab algebra
 
Ai_Project_report
Ai_Project_reportAi_Project_report
Ai_Project_report
 
Data fitting in Scilab - Tutorial
Data fitting in Scilab - TutorialData fitting in Scilab - Tutorial
Data fitting in Scilab - Tutorial
 
Rewriting Java In Scala
Rewriting Java In ScalaRewriting Java In Scala
Rewriting Java In Scala
 
Neural networks using tensor flow in amazon deep learning server
Neural networks using tensor flow in amazon deep learning serverNeural networks using tensor flow in amazon deep learning server
Neural networks using tensor flow in amazon deep learning server
 
Array
ArrayArray
Array
 
CE344L-200365-Lab2.pdf
CE344L-200365-Lab2.pdfCE344L-200365-Lab2.pdf
CE344L-200365-Lab2.pdf
 
Matlab1
Matlab1Matlab1
Matlab1
 
Naïve Bayes.pptx
Naïve Bayes.pptxNaïve Bayes.pptx
Naïve Bayes.pptx
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 

More from pramodkumar1804 (20)

Matlab syntax
Matlab syntaxMatlab syntax
Matlab syntax
 
Matlab strings
Matlab stringsMatlab strings
Matlab strings
 
Matlab simulink
Matlab simulinkMatlab simulink
Matlab simulink
 
Matlab plotting
Matlab plottingMatlab plotting
Matlab plotting
 
Matlab overview 3
Matlab overview 3Matlab overview 3
Matlab overview 3
 
Matlab overview 2
Matlab overview 2Matlab overview 2
Matlab overview 2
 
Matlab overview
Matlab overviewMatlab overview
Matlab overview
 
Matlab numbers
Matlab numbersMatlab numbers
Matlab numbers
 
Matlab matrics
Matlab matricsMatlab matrics
Matlab matrics
 
Matlab m files
Matlab m filesMatlab m files
Matlab m files
 
Matlab loops 2
Matlab loops 2Matlab loops 2
Matlab loops 2
 
Matlab graphics
Matlab graphicsMatlab graphics
Matlab graphics
 
Matlab gnu octave
Matlab gnu octaveMatlab gnu octave
Matlab gnu octave
 
Matlab operators
Matlab operatorsMatlab operators
Matlab operators
 
Matlab functions
Matlab functionsMatlab functions
Matlab functions
 
Matlab differential
Matlab differentialMatlab differential
Matlab differential
 
Matlab decisions
Matlab decisionsMatlab decisions
Matlab decisions
 
Matlab data import
Matlab data importMatlab data import
Matlab data import
 
Matlab colon notation
Matlab colon notationMatlab colon notation
Matlab colon notation
 
Matlab calculus
Matlab calculusMatlab calculus
Matlab calculus
 

Recently uploaded

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 

Recently uploaded (20)

Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 

Matlab polynomials

  • 1. http://www.tutorialspoint.com/matlab/matlab_polynomials.htm Copyright © tutorialspoint.com MATLAB - POLYNOMIALS MATLAB represents polynomials as row vectors containing coefficients ordered by descending powers. For example, the equationP(x) = x4 + 7x3 - 5x + 9 could be represented as: p = [1 7 0 -5 9]; Evaluating Polynomials The polyval functionis used for evaluating a polynomialat a specified value. For example, to evaluate our previous polynomialp, at x = 4, type: p = [1 7 0 -5 9]; polyval(p,4) MATLAB executes the above statements and returns the following result: ans = 693 MATLAB also provides the polyvalmfunctionfor evaluating a matrix polynomial. A matrix polynomialis a polynomial withmatrices as variables. For example, let us create a square matrix X and evaluate the polynomialp, at X: p = [1 7 0 -5 9]; X = [1 2 -3 4; 2 -5 6 3; 3 1 0 2; 5 -7 3 8]; polyvalm(p, X) MATLAB executes the above statements and returns the following result: ans = 2307 -1769 -939 4499 2314 -2376 -249 4695 2256 -1892 -549 4310 4570 -4532 -1062 9269 Finding the Roots of Polynomials The roots functioncalculates the roots of a polynomial. For example, to calculate the roots of our polynomialp, type: p = [1 7 0 -5 9]; r = roots(p) MATLAB executes the above statements and returns the following result: r = -6.8661 + 0.0000i -1.4247 + 0.0000i 0.6454 + 0.7095i 0.6454 - 0.7095i The functionpoly is aninverse of the roots functionand returns to the polynomialcoefficients. For example: p2 = poly(r) MATLAB executes the above statements and returns the following result:
  • 2. p2 = 1.0000 7.0000 0.0000 -5.0000 9.0000 Polynomial Curve Fitting The polyfit functionfinds the coefficients of a polynomialthat fits a set of data ina least-squares sense. If x and y are two vectors containing the x and y data to be fitted to a n-degree polynomial, thenwe get the polynomial fitting the data by writing: p = polyfit(x,y,n) Example Create a script file and type the following code: x = [1 2 3 4 5 6]; y = [5.5 43.1 128 290.7 498.4 978.67]; %data p = polyfit(x,y,4) %get the polynomial % Compute the values of the polyfit estimate over a finer range, % and plot the estimate over the real data values for comparison: x2 = 1:.1:6; y2 = polyval(p,x2); plot(x,y,'o',x2,y2) grid on Whenyourunthe file, MATLAB displays the following result: p = 4.1056 -47.9607 222.2598 -362.7453 191.1250 And plots the following graph: