I’m hoping this is a relatively simple question, but I’m quite new to Mathematica and am struggling with exactly how to express what I’d like it to do. The following isn’t what I’m trying to do, but a very simplified example with the same fundamental issue.
We want to calculate the total weight of a collection of balls 1, 2,…,N. There are only a certain number of types of ball, 1, 2,…T. Ball number x is of type balltype[x]. The weight of a ball of type x is weight[x]. So the weight of ball number x is expressed by weight[balltype[x]]. I want to define the function that is the total weight of all N balls, and it should be something like:
totalweight[weight_, balltype_, N_] := Sum[weight[balltype[x]], {x, 1, N}]
The problem is that I’m not now sure how then to ask for the derivative of totalweight with respect to the weight of a specific type of ball, say weight[1]. The answer should be something like
Sum[Boole[balltype[x]=1],{x,1,N}]
i.e. the total number of balls of type 1 that are in the collection, although there are may be many ways to express this.
My question is: how can I express the function totalweight properly, and how (for example) would I ask for the derivative of totalweight wrt the weight of a particular ball type weight[x]? This seems like a simple sort of problem, but I can’t seem to find anything addressing it, although that could be because I don’t know the right terms to search for. Very many thanks in advance.