# How can we define lots of variables

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.

• 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. – march Oct 27 '16 at 20:08

## 1 Answer

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]]]

• Thanks! This is exactly what I needed. So the point is to use the function Table. – Badshah Oct 27 '16 at 20:22
• similarly vars = Array[p, {10, 10}]; D[p[1, 2]^2, vars[[1, 2]]] – george2079 Oct 27 '16 at 20:45
• 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. – Badshah Oct 28 '16 at 8:14
• @Badshah, for example, using Map: #^2& /@vars will make your squaring of all table elements. – Rom38 Oct 28 '16 at 8:27
• @Rom38 Thanks :) – Badshah Oct 28 '16 at 8:38