%% Analytic Solution to Integral of Polynomial
% This example shows how to use the polyint function to integrate polynomial expressions analytically. Use this function to evaluate indefinite integral expressions of polynomials.
%% Define the Problem
% Consider the real-valued indefinite integral,
% \int \left( 4x^5 - 2x^3 + x + 4 \right) \: dx
% The integrand is a polynomial, and the analytic solution is
% \frac{2}{3}x^6 - \frac{1}{2}x^4 + \frac{1}{2}x^2 + 4x + k
% where k is the constant of integration. Since the limits of integration are unspecified, the integral function family is not well-suited to solving this problem.
%% Express the Polynomial with a Vector
% Create a vector whose elements represent the coefficients for each descending power of x.

p = [4 0 -2 0 1 4];

%
%% Integrate the Polynomial Analytically
% Integrate the polynomial analytically using the polyint function. Specify the constant of integration with the second input argument.

k = 2;
I = polyint(p,k)

% The output is a vector of coefficients for descending powers of x. This result matches the analytic solution above, but has a constant of integration k = 2.
% Copyright 2012 The MathWorks, Inc.