Advanced Mathematics(5/34) Fitting Curves to Data The function polyval will evaluate a polynomial p at x;the form is polyval(p,x). For example:the polynomial -2x2+x+4 is evaluated at x=3, which yields -2 9+3+4,or-11: >>p=[-2141: >polyval (p,3) ans >polyval(p,1:3) -11 ans= 3 -2 -11 The argument x can be a vector. >polyval(p,[5 7]) ans= AW -41 -87 同濟大学 TONGJIUNIVERSITY
Advanced Mathematics(5/34) Fitting Curves to Data The argument x can be a vector
Advanced Mathematics(6/34) Fitting Curves to Data The function polyfit finds the coefficients of the polynomial of the specified degree that best fits the data using a least squares algorithm. Temperatures one aftemnoon For example:The following would fit a polynomial of degree 2 through 70 the data points,storing the values 0 in a vector called coefs. 65 >>×=2:6 >>y=[65677271631 >coefs polyfit (x,y,2) CPHAW coefs= -1.8571 14.8571 41.6000 同停大学 TONGJI UNIVERSITY
Advanced Mathematics(6/34) Fitting Curves to Data ➢ The function polyfit finds the coefficients of the polynomial of the specified degree that best fits the data using a least squares algorithm. For example: The following would fit a polynomial of degree 2 through the data points, storing the values in a vector called coefs
Advanced Mathematics(7/34) Fitting Curves to Data This says that MATLAB has determined that the best quadratic that fits these data points is -1.8571x2+14.8571x+41.6000, Temperatures one afternoon 75 The function polyval can then be used to evaluate the polynomial e 70 at specified values. 65 For example:we could evaluate at every value in the x vector: 60 Time >curve polyval (coefs,x) curve= 同濟大学 AW 63.8857 69.457171.3143 69.4571 63.8857 TONGJI UNIVERSITY
Advanced Mathematics(7/34) Fitting Curves to Data
Advanced Mathematics(8/34) Symbolic Mathematics Symbolic mathematics means doing mathematics on symbols (not numbers!). For example:ata is 2a. The symbolic math functions are in the Symbolic Math Toolbox in MATLAB and toolboxes contain related functions. To find out about the symbolic functions,help can be used: help toolbox\symbolic 同停大学 TONGJI UNIVERSITY
Advanced Mathematics(8/34) Symbolic Mathematics Symbolic mathematics means doing mathematics on symbols (not numbers!). For example: a+a is 2a. The symbolic math functions are in the Symbolic Math Toolbox in MATLAB and toolboxes contain related functions. To find out about the symbolic functions, help can be used:
Advanced Mathematics(9/34) Symbolic Mathematics MATLAB has a type called sym for symbolic variables and expressions;these work with strings. For example:to create a symbolic variable a and perform the addition just described,first a symbolic variable would be created by passing the string a'to the sym function: >>a=sym('a')i >>a+a ans= 2*a @日济大学 TONGJI UNIVERSITY
➢ MATLAB has a type called sym for symbolic variables and expressions; these work with strings. For example: to create a symbolic variable a and perform the addition just described, first a symbolic variable would be created by passing the string ‘a’ to the sym function: Advanced Mathematics(9/34) Symbolic Mathematics