Mathematica Asked on June 16, 2021
Suppose I want to explore $nabla times nabla V$ where $V$ is some scalar function. It basically results in a zero. But I would only know why if I solve it on paper. I wanted to use Mathematica for it and I have found some solutions but I want something cleaner.
pdConv[
Curl[{Subscript[f, x][x, y, z], Subscript[f, y][x, y, z], Subscript[f, z][x, y, z]},
{x, y, z}
] /. {Subscript[f, x] -> Defer[D[V, x]],
Subscript[f, y] -> Defer[D[V, y]],
Subscript[f, z] -> Defer[D[V, z]]}
]
This gives this output:
I did have to do some unpleasant hackery and the other simpler attempt is
pdConv[Curl[{Hold[D[V[x, y, z], x]],
Hold[D[V[x, y, z], y]],
Hold[D[V[x, y, z], z]]}, {x, y, z}]]
This gives this output
which is just perfect, but I don’t like the Hold
appearing in the output and HoldForm
,Inactivate
,Inactive
give weird stuff.
I have copied a function called pdConv
from the Wolfram Blog that converts partial differential expressions to TraditionalForm
. It is really helpful. Here is its definition:
pdConv[f_] := TraditionalForm[f /. Derivative[inds__][g_][vars___] :>
(Defer[D[g[vars],##1]] & ) @@ (Transpose[{{vars}, {inds}}] /. {{var_, 0} :>
Sequence[], {(var_)*1} :> {var}})]
What would be some more cleaner approaches?
If you're willing to tweak a system option, you can do this to make HoldForm be treated the same Hold by differentiation code:
SetSystemOptions["DifferentiationOptions" -> "ExcludedFunctions" ->
Append[
SystemOptions["DifferentiationOptions" -> "ExcludedFunctions"][[-1, -1, -1, -1]],
HoldForm
]
]
You can now use your code with HoldForm
instead of Hold
. I'm a bit surprised that HoldForm
isn't in that list by default. I'll see about adding it to get it to format as you want.
Answered by Itai Seggev on June 16, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP