Say I have an expansion of terms containing functions y[j,t]
and its derivatives, indexed by j
with the index beginning at 0 whose independent variable are t
, like so:
Expr = y[0,t]^2 + D[y[0,t],t]*y[0,t] + y[0,t]*y[1,t] + y[0,t]*D[y[1,t],t] + (y[1,t])^2*y[0,t] +
... etc.
Now I wish to define new functions indexed by i
, call them A[i]
, that collect all terms from the expression above such that the sum of the indices of the factors in each term sums to i
.
In the above case for the terms shown we would have for example
A[0] = y[0,t]^2 + D[y[0,t],t]*y[0,t]
A[1] = y[0,t]*y[1,t] + y[0,t]*D[y[1,t],t]
A[2] = (y[1,t])^2*y[0,t]
How can I get mathematica to assign these terms to these new functions automatically for all i
?
Note: If there is a better way to be indexing functions also feel free to suggest.