www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/IntegrateProductOfTwoPolynomialsExample.m

    %% Integrate Product of Two Polynomials
% Evaluate
%
% $$I = \int_0^2 \left(x^5-x^3+1\right) \left(x^2+1\right) dx$$
%
% Create vectors to represent the polynomials $p(x)=x^5-x^3+1$ and
% $v(x)=x^2+1$.

% Copyright 2015 The MathWorks, Inc.

p = [1 0 -1 0 0 1];
v = [1 0 1];

%%
% Multiply the polynomials and integrate the resulting expression using a
% constant of integration |k = 3|. 
k = 3;
q = polyint(conv(p,v),k)

%%
% Find the value of |I| by evaluating |q| at the limits of integration.
a = 0;
b = 2;
I = diff(polyval(q,[a b]))