I have a function that will compute the derivative matrix operator that transforms coefficients of a Chebyshev interpolant on interval [a, b] of degree n (so n+1 total Chebyshev basis functions T_0, T_1, … T_n) into the coefficients of a degree n-1 chebyshev interpolant on [a, b] that is the exact derivative of the first interpolant. Maybe it could help you:
# derivative matrix
function der_matrix(deg::Int, a::Real=-1, b::Real=1)
N = deg
D = zeros(Float64, N, N+1)
for i=1:N, j=1:N+1
if i == 1
if iseven(i + j)
continue
end
D[i, j] = 2*(j-1)/(b-a)
else
if j < i || iseven(i+j)
continue
end
D[i, j] = 4*(j-1)/(b-a)
end
end
D
end
Oh I forgot to say how to use it. If c are your coefficients for a degree n interpolant on [a, b] then the coefficients of the derivative of that interpolant are der_matrix(n, a, b) * c