I am trying to create an expansion of the form
f[x,y]->Sum[Cn[x] y^n,{n,1,order}]
To replace the function f
by the coefficients cn
. Since the function f
appears in a differential equation, it is useful to get this to work as a set of replacement rules for a pure function, such that the function f
and all its derivatives are replaced. Something like this works:
f->((c0[#1]+c1[#1] #2+c2[#1]#2^2)&)
Curiously, this expression doesn't
f->(( Sum[c[[n]][#1] #2^n,{n,1,order}] )&)
(where c
is a pre-defined vector of coefficients). The index n
is not recognized in the context of defining the pure function (though the same expression defining f[x,y]
would work).
Similarly, if I have several functions and I am trying to define a collection of these replacement rules, this also does not work:
Table[ f[[i]]->f->((c0[[i]][#1]+c1[[i]][#1] #2+c2[[i]][#1]#2^2)&), {i,1,whatever}]
Somehow defining and manipulating a collection of pure functions with an index needs a different syntax. I am curious as for the logic of why this does not work, maybe then I'll understand how to fix it.
Edit: Apologies for the vague question. I think the logic that I was missing is related to attributes of pure functions I was trying to use in replacement rules, as pointed out by acl below. This is related to this question: Function in Table
{n,0,order}
which goes from n=0 up to n=order. But with n=0, C[[n]] is not defined. So maybe C[[n+1]] would fix it. $\endgroup$ – bill s Mar 23 '13 at 10:08