-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjacpoly.m
More file actions
89 lines (73 loc) · 2.32 KB
/
jacpoly.m
File metadata and controls
89 lines (73 loc) · 2.32 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
function p = jacpoly(n, a, b, dom)
%JACPOLY Jacobi polynomials.
% P = JACPOLY(N, ALPHA, BETA) computes a CHEBFUN of the Jacobi polynomial of
% degree N with parameters ALPHA and BETA, where the Jacobi weight function is
% defined by w(x) = (1-x)^ALPHA*(1+x)^BETA. N may be a vector of integers.
%
% P = JACPOLY(N, ALPHA, BETA, DOM) computes the Jacobi polynomials as above,
% but on the interval given by the domain DOM, which must be bounded.
%
% P is computed via the standard recurrence relation for Jacobi polynomials.
%
% See also LEGPOLY, CHEBPOLY.
% Copyright 2014 by The University of Oxford and The Chebfun Developers.
% See http://www.chebfun.org/ for Chebfun information.
% TODO: Use QR to compute the values, as we do in LEGPOLY()?
%% Parse inputs:
if ( nargin < 3 )
error('CHEBFUN:jacpoly:inputs', 'JACPOLY() requires at least 3 inputs.');
end
if ( nargin < 4 )
dom = [-1, 1];
end
% Unbounded domains aren't supported/defined.
if ( any(isinf(dom)) )
error('CHEBFUN:jacpoly:infdomain', ...
'Jacobi polynomials are not defined over an unbounded domain.');
end
%% Setup:
% Force a CHEBTECH basis.
defaultPref = chebfunpref();
pref = defaultPref;
tech = feval(pref.tech);
if ( ~isa(tech, 'chebtech') )
pref.tech = @chebtech2;
end
% Useful values:
nMax = max(n);
nMax1 = nMax + 1;
domIn = dom;
dom = dom([1, end]);
x = chebpts(nMax1, 2);
% TODO: This could also be done using a weighed QR and JACPTS (see LEGPOLY).
%% Recurrence relation:
apb = a + b;
aa = a * a;
bb = b * b;
P = zeros(nMax1);
P(:,1) = 1;
P(:,2) = 0.5*(2*(a + 1) + (apb + 2)*(x - 1));
for k = 2:nMax
k2 = 2*k;
k2apb = k2 + apb;
q1 = k2*(k + apb)*(k2apb - 2);
q2 = (k2apb - 1)*(aa - bb);
q3 = (k2apb - 2)*(k2apb - 1)*k2apb;
q4 = 2*(k + a - 1)*(k + b - 1)*k2apb;
P(:,k+1) = ((q2 + q3*x).*P(:,k) - q4*P(:,k-1)) / q1;
end
%% Assemble output:
[ignored1, ignored2, cc] = unique(n); % Extract required column indices.
cc = nMax1 + 1 - cc; % P is ordered low to high.
C = chebtech2.vals2coeffs(P(:,cc)); % Convert to coefficients
C = fliplr(C); % C is ordered low to high.
% Construct CHEBFUN from coeffs:
p = chebfun(C, dom, pref, 'coeffs');
if ( numel(domIn) > 2)
p = restrict(p, domIn);
end
% Adjust orientation:
if ( size(n, 1) > 1 )
p = p.';
end
end