Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Lecture8

885 views

Published on

Polynomials In Matlab

Published in: Engineering
  • Be the first to comment

Lecture8

  1. 1. Lecture 8 Polynomial In Matlab Eng. Mohamed Awni Electrical & Computer Engineering Dept.
  2. 2. Agenda 2  Finding Roots  Finding polynomial coefficients  Value of a Polynomial  Derivatives of Polynomials  Integrals of Polynomials  Symbolic Math Toolbox Exercise
  3. 3. Finding Roots roots function Solves polynomial equations of the form returns the roots of the polynomial represented by p as a column vector. r = roots(P) • Polynomial coefficients, specified as a vector. • Must include all coefficients, even if 0 For example: • Vector [1 0 1] represents the polynomial 𝑥2+1, • Vector [3.13 -2.21 5.99] represents the polynomial 3.13𝑥2 −2.21𝑥+5.99.
  4. 4. Solve the equation Solve the equation Finding Roots
  5. 5. Finding polynomial coefficients p = poly(r) • r is a row or column vector with the roots of the polynomial • p is a row vector with the coefficients Ex: roots = -3, 2 r = [-3 2]; p = poly(r) p = 1 1 -6 % f(x) = x2 + x -6 Calculate polynomial coefficients
  6. 6. Compute the value of a polynomial for any value of x directly f(x) = 5𝑥3+ 6𝑥2-7𝑥 + 3 Polyval (p, x) • p is a vector with the coefficients of the polynomial • x is a number, variable or expression Value of a Polynomial
  7. 7. k = polyder(p) Derivatives of Polynomials Calculate the derivatives of polynomials • p is the coefficient vector of the polynomial • k is the coefficient vector of the derivative >> p = [3 -2 4]; >> k = polyder(p) k = 6 -2 % dy/dx = 6𝑥 - 2 Ex: f(x) = 3𝑥2 - 2𝑥 + 4
  8. 8. Integrals of Polynomials 6 𝑥2 d𝑥 = 6 𝑥2 dx = 6 * 1 3 𝑥3 = 2 𝑥3 • h is the coefficient vector of the polynomial • g is the coefficient vector of the integral • k is the constant of integration – assumed to be 0 if not present g = polyint(h, k) Calculate the integral of a polynomial >> h = [6 0 0]; >> g = polyint(h) g = 2 0 0 0 % g(x) = 2x3 6𝑥2 dx
  9. 9. Finding roots. Symbolic Math Toolbox Performs calculation symbolically in Matlab environment. >> f=2*x^2 + 4*x -8; >> solve(f,x) In Matlab command window, we will first need to define x as a symbolic. ans = -3.2361 1.2361 >> syms x
  10. 10. Derivative. We wish to take the derivative of function f(x): In Matlab command window, we will first need to define x as a symbolic. >> syms x >> f=x^3-cos(x); >> g=diff(f) Symbolic Math Toolbox >> syms x y >> f=x^2+(y+5)^3; >> diff(f,y) Matlab returns: ans = 3*(y+5)^2 equivalent to Matlab returns: g = 3*x^2+sin(x) g=diff(f)
  11. 11. Symbolic Math Toolbox Integral. >> syms x y >> int(f,x) Matlab returns: ans = 1/3*x^3+(y+5)^3*x >> int(f,y,0,10) Matlab returns: ans = 12500+10*x^2 int(f,x)
  12. 12. Exercises P(x) = 𝑥4 + 7𝑥3 - 5x + 9 • Find the roots of the ploynomial P(x) • Evaluate the polynomial P(x) for x=4 and x=6 • Calculate the d p(x)/dx • Calculate the 𝑝(𝑥)

×