SlideShare a Scribd company logo
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

PDF
AP Calculus Slides February 14, 2008
PPT
Core 3 Functions 1
PPT
Core 3 Functions 3
PPTX
Lecture one
PPT
Matlab Nn Intro
PPTX
Arrays.pptx
PPTX
Lecture two
PDF
Day 5 examples
AP Calculus Slides February 14, 2008
Core 3 Functions 1
Core 3 Functions 3
Lecture one
Matlab Nn Intro
Arrays.pptx
Lecture two
Day 5 examples

What's hot (18)

PPT
Arrays and Pointers
PPTX
PPTX
Python - Numpy/Pandas/Matplot Machine Learning Libraries
PPTX
PPTX
Pointers
PDF
Matlab integration
PDF
Intoduction to numpy
PPTX
Pointers
PDF
Introduction to NumPy (PyData SV 2013)
PPTX
Map filter reduce in Python
PDF
Introduction to matlab
PDF
A02
PPTX
statistical computation using R- an intro..
PPTX
Introduction to numpy
PDF
Introduction to TensorFlow, by Machine Learning at Berkeley
PDF
Scala. Introduction to FP. Monads
PDF
Extending built in objects
PPTX
Introduction to numpy Session 1
Arrays and Pointers
Python - Numpy/Pandas/Matplot Machine Learning Libraries
Pointers
Matlab integration
Intoduction to numpy
Pointers
Introduction to NumPy (PyData SV 2013)
Map filter reduce in Python
Introduction to matlab
A02
statistical computation using R- an intro..
Introduction to numpy
Introduction to TensorFlow, by Machine Learning at Berkeley
Scala. Introduction to FP. Monads
Extending built in objects
Introduction to numpy Session 1
Ad

Viewers also liked (12)

PPTX
Inundacions Octubre 1930
PDF
Genetics 2008
PDF
El trabajo de dos alumnos
PDF
APPLICATION FOR PARTNERSHIP OR SUPPORT FOR SPORTS
PPTX
Gabrielrojas gobierno en linea
PPTX
Propuesta para Referentes
PPTX
Government Procurement Benefits of Green Proposals Services
DOCX
Edilsa palacios actividad1_mapa_cpdf.jpg
PPTX
K igama
PDF
Matlab loops
PPTX
Witte mars
PDF
Matlab operators
Inundacions Octubre 1930
Genetics 2008
El trabajo de dos alumnos
APPLICATION FOR PARTNERSHIP OR SUPPORT FOR SPORTS
Gabrielrojas gobierno en linea
Propuesta para Referentes
Government Procurement Benefits of Green Proposals Services
Edilsa palacios actividad1_mapa_cpdf.jpg
K igama
Matlab loops
Witte mars
Matlab operators
Ad

Similar to Matlab polynomials (20)

PPTX
Lecture three
PPTX
Matlab polynimials and curve fitting
PDF
Advanced matlab codigos matematicos
PPTX
Polynomials and Curve Fitting in MATLAB
PPTX
02 MATLAB Polynomials.pptx using of matlab
PDF
Matlab variables
PPTX
unit-5 Data Wrandling weightage marks.pptx
PPTX
MATLAB for Engineers ME1006 (1 for beginer).pptx
PDF
Lecture 3 - Introduction to Interpolation
PDF
maXbox starter69 Machine Learning VII
PPTX
NUMPY [Autosaved] .pptx
PDF
3_MLE_printable.pdf
PDF
Matlab algebra
PDF
Ai_Project_report
PPTX
In- Built Math function in java script..
PPT
Apply Type functions in R.ppt ppt made by me
PPTX
UNIT – 3.pptx for first year engineering
PDF
Data fitting in Scilab - Tutorial
PPT
Rewriting Java In Scala
DOCX
PPS 7.7 RECURSION, AS A DIFFERENT WAY OF SOLVING PROBLEMS. EXAMPLE PROGRAMS
Lecture three
Matlab polynimials and curve fitting
Advanced matlab codigos matematicos
Polynomials and Curve Fitting in MATLAB
02 MATLAB Polynomials.pptx using of matlab
Matlab variables
unit-5 Data Wrandling weightage marks.pptx
MATLAB for Engineers ME1006 (1 for beginer).pptx
Lecture 3 - Introduction to Interpolation
maXbox starter69 Machine Learning VII
NUMPY [Autosaved] .pptx
3_MLE_printable.pdf
Matlab algebra
Ai_Project_report
In- Built Math function in java script..
Apply Type functions in R.ppt ppt made by me
UNIT – 3.pptx for first year engineering
Data fitting in Scilab - Tutorial
Rewriting Java In Scala
PPS 7.7 RECURSION, AS A DIFFERENT WAY OF SOLVING PROBLEMS. EXAMPLE PROGRAMS

More from pramodkumar1804 (20)

PDF
Matlab syntax
PDF
Matlab strings
PDF
Matlab simulink
PDF
Matlab plotting
PDF
Matlab overview 3
PDF
Matlab overview 2
PDF
Matlab overview
PDF
Matlab numbers
PDF
Matlab matrics
PDF
Matlab m files
PDF
Matlab loops 2
PDF
Matlab graphics
PDF
Matlab gnu octave
PDF
Matlab operators
PDF
Matlab functions
PDF
Matlab differential
PDF
Matlab decisions
PDF
Matlab data import
PDF
Matlab colon notation
PDF
Matlab calculus
Matlab syntax
Matlab strings
Matlab simulink
Matlab plotting
Matlab overview 3
Matlab overview 2
Matlab overview
Matlab numbers
Matlab matrics
Matlab m files
Matlab loops 2
Matlab graphics
Matlab gnu octave
Matlab operators
Matlab functions
Matlab differential
Matlab decisions
Matlab data import
Matlab colon notation
Matlab calculus

Recently uploaded (20)

PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Lesson notes of climatology university.
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
RMMM.pdf make it easy to upload and study
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Pharma ospi slides which help in ospi learning
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Cell Structure & Organelles in detailed.
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Computing-Curriculum for Schools in Ghana
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Lesson notes of climatology university.
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
VCE English Exam - Section C Student Revision Booklet
Final Presentation General Medicine 03-08-2024.pptx
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Supply Chain Operations Speaking Notes -ICLT Program
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Microbial diseases, their pathogenesis and prophylaxis
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
RMMM.pdf make it easy to upload and study
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Pharma ospi slides which help in ospi learning
Chinmaya Tiranga quiz Grand Finale.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
01-Introduction-to-Information-Management.pdf
Cell Structure & Organelles in detailed.
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Computing-Curriculum for Schools in Ghana

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: