# Question:Clenshaw derivative recurrence

## Question:Clenshaw derivative recurrence

Maple

Hi! I have been trying to calculate the value of theClenshaw derivative. I can get the regular clenshaw to work but not the derivative. I'm going off of the thread (https://scicomp.stackexchange.com/questions/27865/clenshaw-type-recurrence-for-derivative-of-chebyshev-series). (P.s notice I have halfed the A[z+1] term. I have tried both ways but the overall result is wrong so I am guessing something more important is wrong).

This is my code so far

```Clenshaw_Dx_1D:=proc(z,C,Nm,s)
local i,k,A,B: global Clen1D_Dx:

A := Vector(z..Nm+1+z);
B := Vector(z..Nm+1+z);

for k from Nm-1+z by -1 to 1+z do
A[k] := C[k] + 2*s*A[k+1] - A[k+2]:
od:

for k from Nm-1+z by -1 to 1+z do
B[k] := 2*A[k+1] + 2*s*B[k+1] - B[k+2]:
od:
Clen1D_Dx :=  A[z+1]/2 + s*B[1+z] - B[2+z]:

end:
```

Where z could be 0 or 1 depending on what index your C array starts at. C is the array of chebyshev coefficients of a Chebyshev series appromating u(x) for example. The Chebycoeff1D procedure calculates the Chebyshev coefficients  and the code below calls the procedure for a specific function. Try it with some values of xM, for example 4-10.

```Chebycoeff1D:=proc(express,Nn,C2,A,B)
local Cfac,fac1x,fac2x,k,K;

fac1x:=Pi/Nn;
for k from 1 to Nn do
Cfac(k):=eval(subs(x=evalf(cos(fac1x*(k-0.5)))*A+B,evalf(express)));
od; unassign('k'):
for K from 1 to Nn do
fac2x:=Pi*(K-1)/Nn;
od:
end:
```
```nn := 1.0:
Lc := 0.0: Rc := 1.0:
func:=nn*sin(2*Pi*x)+0.5*nn*sin(Pi*x):
Chebycoeff1D(func,xM+1,C,0.5*(Rc-Lc),0.5*(Rc+Lc)):
```

Once you have the C array call Clenshaw_Dx_1D. For example

`Clenshaw_Dx_1D(0,C,xM+1,0.0);  # Evalutes f'(x) in the middle of the domain.`

Check with

`subs(x=0.5, diff(func,x));`

The overall "pattern/shape" of the derivative values is correct, just not the amplitude/values. Any help here? Where is the Clenshaw derivative procedure going wrong. ﻿