1 ## Copyright (C) 1996-2012 John W. Eaton
3 ## This file is part of Octave.
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {} polyint (@var{p})
21 ## @deftypefnx {Function File} {} polyint (@var{p}, @var{k})
22 ## Return the coefficients of the integral of the polynomial whose
23 ## coefficients are represented by the vector @var{p}. The variable
24 ## @var{k} is the constant of integration, which by default is set to zero.
25 ## @seealso{polyder, polyval}
28 ## Author: Tony Richardson <arichard@stark.cc.oh.us>
32 function retval = polyint (p, k)
34 if (nargin < 1 || nargin > 2)
40 elseif (! isscalar (k))
41 error ("polyint: the constant of integration must be a scalar");
44 if (! (isvector (p) || isempty (p)))
45 error ("polyint: argument must be a vector");
56 ## Convert to column vector
60 retval = [(p ./ [lp:-1:1]), k];
66 %! assert (polyint(A),polyint(A,0));
67 %! assert (polyint(A),polyint(A'));
68 %! assert (polyint(A),[1, 1, 1, 0]);
69 %! assert (polyint(A,1),ones(1,4));
73 %! B = [length(A):-1:1];
74 %! assert (polyint(A),[1./B, 0]);
77 %!error polyint(ones(2,2))