4
$\begingroup$

I'm trying to define an array of differential operators, so that I can choose which one to use in a sum using the index. That is, I'm trying to write,

$$\mathrm{del} = \{\partial_t,\partial_x,\partial_y,\partial_z\}$$

so that I can then use, for example,

$$\mathrm{del}[0] f(t) = \mathrm{D}[f(t),t]$$

but even trying to define $\mathrm{del}$ is not working. (For those curious, this is so that I can define a tensor calculus sum in general relativity.)

$\endgroup$
2
  • $\begingroup$ There are some packages for GR; I've never used them, but you could try googling mathematica general relativity package and maybe you'll find something useful. $\endgroup$
    – corey979
    Jan 8, 2018 at 19:08
  • $\begingroup$ @corey979 Yes I’m working with one but for what I want to do, defining it myself is simpler as they have bad interfaces. $\endgroup$ Jan 8, 2018 at 20:22

1 Answer 1

6
$\begingroup$

One possibility is

del = Table[With[{k = k}, D[#, k] &], {k, {t, x, y, z}}];

Then,

del[[1]][x^2]
del[[2]][x^2]
Through[del[x^2]]
(* 0 *)
(* 2*x *)
(* {0, 2 x, 0, 0} *)

If you really want it to be indexed starting at zero, then redefine

Clear@del
Do[With[{var = {t, x, y, z}[[k]]}, del[k - 1] = D[#, var] &], {k, 4}]

Then,

del[0][x^2]
del[1][x^2]
(* 0 *)
(* 2*x *)
$\endgroup$

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.