I am new to Mathematica and some things I do not understand. Right now I need to write an algorithm which takes a polynomial in many variables, I denote it by $p_{i,j}$, and then I want to apply a differential operator on it. Something like $\sum_{i,j,k,l}p_{i+k-2,j+l}\partial p_{i,j}\partial p_{k,l}$ where $\partial p_{i,j}$ means differentiate the polynomial with respect to $p_{i,j}$. The first problem I am encountering right now is how to define a polynomial in these variables. I used Symbolize in Mathematica to define variables with subscript. The problem I have, how to go through this sum in the differential operator? I can't just put i and j in the subscript and then use a for loop. I want something like a list L which stores these variables and then if I want to differentiate with respect to $p_{i,j}$, I tell Mathematica to differentiate with respect to L[i,j].

I don't know how to do this and couldn't find something using Google.

  • 1
    $\begingroup$ It would be useful if you could include the code that you have so far. In addition, giving an example with the desired output would also be useful. Please edit your post to include these. $\endgroup$
    – march
    Commented Oct 27, 2016 at 20:08

1 Answer 1


Not sure if this is what you want. The first command creates your list of variables and the second one takes a derivative of a very simple function with respect to one of the variables in the list.

vars = Table[Subscript[p, i, j], {i, 1, 10}, {j, 1, 10}]
D[ Subscript[p, 1, 2]^2,vars[[1,2]]]
  • $\begingroup$ Thanks! This is exactly what I needed. So the point is to use the function Table. $\endgroup$
    – Badshah
    Commented Oct 27, 2016 at 20:22
  • 2
    $\begingroup$ similarly vars = Array[p, {10, 10}]; D[p[1, 2]^2, vars[[1, 2]]] $\endgroup$
    – george2079
    Commented Oct 27, 2016 at 20:45
  • $\begingroup$ I have one more question: How can I define functions using this table? I tried f[vars[[1,2]]_]:=vars[[1,2]]^2 and then I tried to differentiate this f, but it didnt work. $\endgroup$
    – Badshah
    Commented Oct 28, 2016 at 8:14
  • 2
    $\begingroup$ @Badshah, for example, using Map: #^2& /@vars will make your squaring of all table elements. $\endgroup$
    – Rom38
    Commented Oct 28, 2016 at 8:27
  • $\begingroup$ @Rom38 Thanks :) $\endgroup$
    – Badshah
    Commented Oct 28, 2016 at 8:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.