Polynomials - Example 7: Estimate the definite integral -22 (x5+2x4-3x2+7x+12)dx.
- Choose equal subinterval widths x = (b-a)/n and sample points xi* to be each subinterval’s midpoint, i.e. xi*=a+(2*i-1)*(b-a)/2n, for a=-2, b=2, and n=100.
- Do this first with the polynomial’s formula.
- a=-2;
- b=2;
- n=100;
- dx = (b-a)/n;
- xstar = a+dx/2:dx:b-dx/2;
- Rn = sum(xstar.^5+2*xstar.^4-3*xstar.^2+7*xstar+12)*dx
- Repeat with “polyval”.
- Rn = sum(polyval(p,xstar))*dx
- In each case, you should get the approximation to be about 57.5931.
- What is the actual value of this integral?
- Answer: 288/5.
Polynomials – polyder - Using the command “polyder”, we can differentiate a polynomial, polynonial product, or polynomial quotient!
- Syntax:
- “polyder(p)” returns the derivative of the polynomial whose coefficients are the elements of vector p.
- “[K] = polyder(a,b)” returns the derivative of polynomial a*b.
- “[Q,D]” = polyder(b,a) returns the derivative of the polynomial ratio b/a, represented as Q/D.
- Try this command with
- p = [1 2 0 -3 7 12]
- a = [1 1]
- b = [1 2 1]
- Do your results agree with calculations done by hand?
Polynomials – polyint - Using the command “polyint”, we can integrate a polynomial!
- Syntax:
- “polyint(p,K)” returns a polynomial representing the integral of polynomial p, using a scalar constant of integration K.
- “polyint(p)” assumes a constant of integration K=0.
- Try this command with
- p = [1 2 0 -3 7 12]
- K = 7
- Do your results agree with calculations done by hand?
- We can use the command “polyfit” to fit a polynomial to a set of data via a least-squares fit.
- Syntax: p = polyfit(x, y, n) will fit a polynomial of degree n to data given as ordered pairs (xi,yi) for i = 1, 2, … , m.
Do'stlaringiz bilan baham: |