# Taking the derivative of a function with indexed variables

I have a number of functions that depend on a variable x. I am using a second, integer variable to index these functions, i.e. something like

f[x_, 1] = a
f[x_, 2] = b x + c


When taking derivatives of these functions with D, it works the way I intend, i.e.

D[f[x, 1], x]
D[f[x, 2], x]


returns 0 respectively b. Now, however, I have a set of differential equations involving derivatives of these functions. These are expressed by Mathematica as

Derivative[1, 0][f][x, 1]
Derivative[1, 0][f][x, 2]


which remains unevaluated. Is there any way to have Derivative ignore the second variable? More specifically, I would like to have a way of doing something along the lines of

Derivative[g][x]


and then replacing g by f[x, 1]. I guess I could just assign specific names to each of the functions f[x, k], but in the end I want to sum them all up

Sum[f[x, k],{k, 1, n}]


for which it would be convienient to have some index variable rather than writing out the sum over different functions. Maybe I am approaching the whole idea of indexing functions in the wrong way?

You can put the index in the first pair of brackets, and the variable in the second, like so:

f[x_] = a;
f[x_] := b x + c;


(Note that the second assignment uses SetDelayed instead of Set. This is necessary because the variable x occurs on the right-hand-side).

You can view f[index] as the function acting on x. The derivatives are computed as follows:

f'[x]

0

f'[x]

 b


Computing the sum is then as easy as Sum[f[k][x],{k,1,n}]

• +1 For currying. Not a trick used often enough here, IMHO! – evanb Sep 12 '14 at 17:24
• Thanks for the answer! I did not know that using multiple levels of arguments was possible. – Andreas Sep 12 '14 at 19:27