Is it possible for Mathematica to solve an equation like $\nabla f(\mathbf{r}) = - \mathbf{E}(\mathbf{r})$ for $f(\mathbf{r})$?

I tried Reduce[Grad[f[x,y,z],{x,y,z}]== -{ex,ey,ez}, f] but that does not work.

  • $\begingroup$ Could you please provide a complete code snippet ? Something that we could copy paste into our notebooks and see the actual error ? $\endgroup$ – stathisk Nov 12 '13 at 17:32
  • 4
    $\begingroup$ What for? You need not playing with Mathematica for this: $$ f(\mathbf{r}) = f(\mathbf{r_0})- \int \mathbf{E}(\mathbf{r}) d\mathbf{r}$$ $\endgroup$ – Artes Nov 12 '13 at 17:35
  • $\begingroup$ It's a differential equation so you need to use DSolve $\endgroup$ – Simon Woods Nov 12 '13 at 18:53

I'll try to combine Artes and Simon Woods comments in an answer.

Given is the electric field as el = {ex, ey, ez} = {er, e\[Theta], ez} in Cartesian and Cylindrical coordinates, respectively.

Solving the differential equation can be done in Cartesian coordinates with

DSolve[Grad[f[x, y, z], {x, y, z}] == {ex, ey, ez}, 
 f[x, y, z], {x, y, z}]

{{f[x, y, z] -> ex x + ey y + ez z + C[1]}}

Or simply by integration, where one has to parametrize the integration variable

Integrate[{ex, ey, ez}.{x t, y t, z t}, {t, 0, Sqrt[2]}]

ex x + ey y + ez z

Remember the constant integration factor, which is set to zero here.

Integration is also easily done in different coordinate systems, such as cylindrical ones

Integrate[{er, e\[Theta], ez}.{r t, r \[Theta] t, z t}, {t, 0, 

er r + ez z + e\[Theta] r \[Theta]

How to use DSolve[] in this case I don't know yet, as

DSolve[Grad[f[r, \[Theta], z], {r, \[Theta], z}, 
   "Cylindrical"] == {er, e\[Theta], ez}, 
 f[r, \[Theta], z], {r, \[Theta], z}]

does not work.

I know this is pretty elementary, but maybe it can help others. Please help to further improve this answer!

| improve this answer | |
  • $\begingroup$ It is about solving of a system consisting of three time-independent partial differential equations, each of the first order. As much as I know neither DSolve, not NDSolve can do this. Please correct me if I missed something. $\endgroup$ – Alexei Boulbitch Nov 13 '13 at 12:17
  • $\begingroup$ @AlexeiBoulbitch Works for me: DSolve[{D[F[x, y, z], {{x, y, z}}] == D[x + x y + z y + x y z, {{x, y, z}}]}, F, {x, y, z}] (V9.0.1). Of course the system is integrable only if the curl of the vector field is zero. $\endgroup$ – Michael E2 Nov 13 '13 at 13:19

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.