%% Integrate and Differentiate Polynomials
% This example shows how to use the polyint and polyder functions to analytically integrate or differentiate any polynomial represented by a vector of coefficients.
% Use polyder to obtain the derivative of the polynomial p(x) = x^3 - 2x - 5. The resulting polynomial is q(x) = \frac{d}{dx} p(x) = 3x^2 - 2.

p = [1 0 -2 -5];
q = polyder(p)

%
% Similarly, use polyint to integrate the polynomial p(x) = 4x^3 - 3x^2 + 1. The resulting polynomial is q(x) = \int p(x)dx = x^4 - x^3 + x.

p = [4 -3 0 1];
q = polyint(p)

%
% polyder also computes the derivative of the product or quotient of two polynomials. For example, create two vectors to represent the polynomials a(x) = x^2 + 3x + 5 and b(x) = 2x^2 + 4x + 6.

a = [1 3 5];
b = [2 4 6];

%
% Calculate the derivative \frac{d}{dx} \left[ a(x)b(x) \right] by calling polyder with a single output argument.

c = polyder(a,b)

%
% Calculate the derivative \frac{d}{dx} \left[ \frac{a(x)}{b(x)} \right] by calling polyder with two output arguments. The resulting polynomial is
% \frac{d}{dx} \left[ \frac{a(x)}{b(x)} \right] =
% \frac{-2x^2-8x-2}{4x^4+16x^3+40x^2+48x+36} = \frac{q(x)}{d(x)}.

[q,d] = polyder(a,b)

% Copyright 2015 The MathWorks, Inc.