ENGINEERING COURSES FOR UNDERGRADUATE STUDENTS
Would you like to react to this message? Create an account in a few clicks or log in to continue.
ENGINEERING COURSES FOR UNDERGRADUATE STUDENTS

LECTURES & APPLICATIONS
 
HomeHome  Latest imagesLatest images  SearchSearch  RegisterRegister  Log inLog in  

 

 Polynomials and Fitting

Go down 
AuthorMessage
Eng.Saeed Almalowi




Posts : 38
Join date : 2009-10-27
Location : UNITED STATE OF AMERICA, STATE COLLEGE,PA

Polynomials and Fitting Empty
PostSubject: Polynomials and Fitting   Polynomials and Fitting Icon_minitimeThu Oct 29, 2009 6:51 am

Matlab can treat a vector as a polynomial. It will assume that the numbers represent the coefficients of the polynomial going from highest-order to lowest order.

>>p = [1 2 2 4 1]

can represent the polynomial x^4 + 2x^3 + 2x^2 + 4x + 1. There are a number of functions that use this representation of polynomials:

>>roots(p)

gives you the roots of the polynomail represented by the vector p.

>>polyval(p,4)

gives you the value of the polynomial p when x = 4. Similarly,

>>polyval(p,[1:10])

gives you the value of the polynomial evaluated at each of the points in the vector. (It returns another vector the same size.)

You can fit polynomials to data sets using this representation and a function called curvefit.

>>[p, fitted] = curvefit(x,y,n)

fits the data in x and y to an nth order polynomial (using 1 gives you a straight line, 2 gives you a quadratic, etc), and plots both the data and the fitted curve for you. It returns p, the polynomial representing the equation of the fitted curve, and fitted, the data points you get from the curvefit for each of the x's in your data set.

You can use polyval and the fitted polynomial p to predict the y value of the data you've fitted for some other x values.

>>ypred = polyval(p,xvalues)
Back to top Go down
http://www.aalhameed1.net
 
Polynomials and Fitting
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
ENGINEERING COURSES FOR UNDERGRADUATE STUDENTS :: ENGINEERING PROGRAMS/SOFT WARE :: MATLAB PROGRAM FORUM-
Jump to: