Open ajt60gaibb opened 4 years ago
Here's the code for multmat1d_ultraS
using Clenshaw's algorithm:
function M = multmat1d_ultraS_clenshaw(n, a, Mx, lambda)
%MULTMAT1D_ULTRAS Compute the 1D N x N multiplication matrix for the function
%
% f(x,y) = sum_j a(j) C^{(lambda)}_j(x)
%
% Alex Townsend, April 2020.
m = 2*n;
Mold = 0*Mx;
Ms = 0*Mx;
twoMx = 2*Mx;
I = speye(m);
for k = n:-1:2
Mnew = a(k)*I + (k+lambda-1)/(k)*twoMx*Ms - (k+2*lambda-1)/(k+1)*Mold;
Mold = Ms; Ms = Mnew;
end
M = a(1)*I + lambda*twoMx*Ms - lambda*Mold;
M = M(1:n,1:n);
end
There is the possibility of using Clenshaw's algorithm to build multmats. For example, here is the code of ChebT (I put this inside
+util
for a fair comparison):It can be faster than the three-term recurrence in certain situations.
The precise speedup depends on
n
andr
. Do we want to use clenshaw instead of three-term recurrence?