1 ## Copyright (C) 2008 Eric Chassande-Mottin
3 ## This program is free software; you can redistribute it and/or modify
4 ## it under the terms of the GNU General Public License as published by
5 ## the Free Software Foundation; either version 3 of the License, or
6 ## (at your option) any later version.
8 ## This program is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 ## GNU General Public License for more details.
13 ## You should have received a copy of the GNU General Public License
14 ## along with this program; If not, see <http://www.gnu.org/licenses/>.
17 ## @deftypefn {Function File} {@var{y} = } laguerre (@var{x},@var{n})
18 ## @deftypefnx {Function File} {[@var{y} @var{p}]= } laguerre (@var{x},@var{n})
20 ## Compute the value of the Laguerre polynomial of order @var{n} for each element of @var{x}
24 function [y,p]=laguerre(x,n)
28 elseif (n < 0 || !isscalar (n))
29 error("second argument 'n' must be a positive integer");
40 % recursive calculation of the polynomial coefficients
44 p(2) = ((2*k-1)*p1(1)-p1(2))/k;
46 p(3:k) = ((2*k-1)*p1(2:k-1)-p1(3:k)-(k-1)*p0(1:k-2))/k;
48 p(k+1) = ((2*k-1)*p1(k)-(k-1)*p0(k-1))/k;
63 %! assert(y1-y2,0,eps);
70 %! assert(y1-y2,0,eps);
77 %! assert(y1-y2,0,eps);
82 %! p3=[-1/6 9/6 -18/6 1];
84 %! assert(y1-y2,0,eps);
89 %! p4=[1/24 -16/24 72/24 -96/24 1];
91 %! assert(y1-y2,0,eps);