8:Advanced Mathematics Part 1:Fitting Curves to Data Part 2:Symbolic Mathematics ▣Part3:Calculus CDHAW @月协大学 TONGJI UNIVERSITY
8: Advanced Mathematics Part 1: Fitting Curves to Data Part 2: Symbolic Mathematics Part 3: Calculus
Advanced Mathematics(1/34) Fitting Curves to Data In this part,selected advanced mathematics and related built-in functions in the MATLAB software are introduced. >Fitting a curve to the data is often desired.Curve fitting is finding the curve that best fits the data. MATLAB has several curve-fitting functions.Some of the simplest curves are polynomials of different degrees, which are described next. 日濟大学 AW TONGJI UNIVERSITY
➢ In this part, selected advanced mathematics and related built-in functions in the MATLAB software are introduced. ➢ Fitting a curve to the data is often desired. Curve fitting is finding the curve that best fits the data. ➢ MATLAB has several curve-fitting functions. Some of the simplest curves are polynomials of different degrees, which are described next. Advanced Mathematics(1/34) Fitting Curves to Data
Advanced Mathematics(2/34) Fitting Curves to Data Polynomials Simple curves are polynomials of different degrees or orders.The degree is the integer of the highest exponent in the expression. For example: A straight line is a first-order(or degree 1)polynomial of the form ax b,or more explicitly ax+b. A quadratic is a second-order (or degree 2)polynomial of the form ax2 +bx +c. A cubic (degree 3)is of the form ax3+bx2+cx+d. 翻月停大学 TONGJI UNIVERSITY
Advanced Mathematics(2/34) Fitting Curves to Data
Advanced Mathematics(3/34) Fitting Curves to Data The built-in functions sym2poly and poly2sym convert from symbolic expressions to polynomial vectors and vice versa. For example: >>myp=[12-43]: >poly2sym(myp) ans= x^3+2*×^2-4*X+3 >>mypo1y=[20-105]: >poly2sym(mypoly) ans= 2*x^4-×^2+5 >sym2poly (ans) ans @日济大学 2 TONGJIUNIVE具sITY
Advanced Mathematics(3/34) Fitting Curves to Data ➢ The built-in functions sym2poly and poly2sym convert from symbolic expressions to polynomial vectors and vice versa. For example:
Advanced Mathematics(4/34) Fitting Curves to Data The roots function in MATLAB can be used to find the roots of an equation represented by a polynomial. For example:for the mathematical function 4x3-2x2-8x+3 to solve the equation f(x)=0: >>roots([4-2-83]) ans= -1.3660 1.5000 0.3660 CDHAW @月协大学 TONGJI UNIVERSITY
Advanced Mathematics(4/34) Fitting Curves to Data
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