I'm trying to define a differential operator indexed by a natural number $n$, with the definition varying depending on the parity of $n$. Here's what I wrote:
For[g = 3, g <= 10, g++, If[EvenQ[g], Dop[g] = -dF[g/2]*D[#, x] &, Dop[g] = A'[z] dF[(g + 1)/2]*# &] ]
dF is just a function that receives an integer argument. The problem here is that the argument of
dF does not get evaluated until after when I give the operator itself an argument.
For instance if, right after the
For, one evaluates
Dop[f[x]], we see that it's using $g=11$. I tried using
Evaluate as suggested here, but it still doesn't work. For example
For[g = 3, g <= 10, g++, If[EvenQ[g], Dop[g] = -dF[Evaluate[g/2]]*D[#, x] &, Dop[g] = A'[z] dF[Evaluate[(g + 1)/2]]*# &] ]
does not do anything and
For[g = 3, g <= 10, g++, If[EvenQ[g], Dop[g] = Evaluate[-dF[g/2]*D[#, x]] &, Dop[g] = Evaluate[A'[z] dF[(g + 1)/2]*#] &] ]
only works in the odd case. In the even case, I'm assuming it is forcing the derivative to be done right away, because the operator vanishes.
There was also the suggestion of using SetDelayed instead of a
For in the above answer, but
Dop have different definitions, so I'm not sure how to do that without overwritting these (notice that the
Fors only start on $g=3$).
I'd appreciate any insight here. Thank you!