-
Notifications
You must be signed in to change notification settings - Fork 20
/
hermitepolynomial.m
50 lines (42 loc) · 1.16 KB
/
hermitepolynomial.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
function p=hermitepolynomial(n)
% HERMITEPOLYNOMIAL - Hermite polynomial
%
% Syntax:
% p = hermitepolynomial(n)
%
% In:
% n - Polynomial order
%
% Out:
% p - Polynomial coefficients (starting from greatest order)
%
% Description:
% Forms the Hermite polynomial of order n.
%
% See also:
% POLYVAL, ROOTS
% History:
% May 18, 2010 - Initial version (asolin)
% Copyright (c) 2010 Arno Solin
%
% This software is distributed under the GNU General Public
% Licence (version 2 or later); please refer to the file
% Licence.txt, included with the software, for details.
%% The "physicists' Hermite polynomials"
% To get the differently scaled "probabilists' Hermite polynomials"
% remove the coefficient *2 in (**).
% Check the input argument values
if (nargin ~= 1) error('Too few arguments.'); end;
n = fix(max(n,0));
% Allocate space for the polynomials and set H0(x) = -1
H = zeros(n+1);
r = 1:n;
H(1) = -1;
% Calculate the polynomials starting from H2(x)
for i=2:n+1
H(i,2:n+1) = H(i,2:n+1) + H(i-1,1:n)*(-1)*2; % (**)
H(i,1:n) = H(i,1:n) + H(i-1,2:n+1).*r;
end
% Return results
p=fliplr(H(n+1,:)).*(-1)^(n+1);
end