I have the following example vector calculus code

gg := g[x, y, z];
gg[x_, y_, z_] := g[x, y, z];
Format[g[x, y, z]] = g;

f = Grad[x*gg, {x, y, z}];   
f // MatrixForm // pdConv

which produces the output $$ \displaystyle{\left( \begin{array}{c} x \frac{\partial g }{\partial x}+g\\ x \frac{\partial g }{\partial y}\\ x \frac{\partial g }{\partial z}\\ \end{array} \right)}$$ But I would like the output format to be $$ x \nabla g + \left( \begin{array}{c} g \\ 0 \\ 0 \\ \end{array} \right) $$

Is there a way to accomplish this?

The above of course is a simple example. I would like to have a code that finds the gradient terms and extracts them.

I'm using the pdConv function

  • $\begingroup$ Del is undefined: reference.wolfram.com/language/ref/Del.html I would say define del and then expand it? $\endgroup$ – CA Trevillian Jun 11 at 3:58
  • $\begingroup$ @CATrevillian the hard part is recognizing when the partials in a 3D vector (ie a list) can be combined after performing a calculation $\endgroup$ – RFS Jun 11 at 16:33
  • $\begingroup$ You could possibly define your own simplification rule? I will visit this later today and provide the reference if I can find it. $\endgroup$ – CA Trevillian Jun 11 at 21:33
  • $\begingroup$ @CATrevillian Thank you! $\endgroup$ – RFS Jun 12 at 1:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.