0

I was trying to define define the differential operators $\partial_{x_i}$ for every $x_i$ in some list and ran into a problem. The list is defined as follows in Mathematica.

n = 5;

x = ConstantArray[0, {n}];

Do[x[[i]] = Subscript[x, i], {i, 0, 5}]

Now for a single $x_i$, say $x_1$, one can define the corresponding differential operator as follows

diff1 = (D[#, x[[1]]] &)

The output is $\frac{\partial \text{$\#$1}}{\partial x[[1]]}\&$, which is what we want. But the problem arises if we try to do this in an automated way, for which we would use something like the following code (for illustrator purposes let the loop run only from $i=1$ to $1$ here),

Do[diff1 = (D[#, x[[i]]] &), {i, 1, 1}]

This returns $\frac{\partial \text{$\#$1}}{\partial x[[i]]}\&$, which is not what we wanted. The index $i$ has somehow survived the do loop; it should have been replaced by a $1$.

What is the reason of this and how might I solve it?

Inzinity
  • 193
  • 3

0 Answers0