I have the following three-dimensional electric field:

e[r_, θ_, ϕ_, t_] := (Sin[θ]/r)*(Cos[r - t] - Sin[r - t]/r)*{0, 0, 1}

where the {0,0,1} vector is the unit Phi vector. How can I plot the electric field lines in three-dimensional space, with spherical coordinates?

  • $\begingroup$ As far I know, MMA cannot plot any 3D function in other coordinate system than Cartesian. This means that your vector function in other Coordinate System should be transformed to that in a Cartesian one... $\endgroup$ – José Antonio Díaz Navas Feb 11 '18 at 18:39

Generate the TransformedField and then plot it.

tf = TransformedField["Spherical"->"Cartesian",e[r,θ,φ,1],{r,θ,φ}->{x,y,z}]

This plots the vector field at t==1.

| improve this answer | |
  • $\begingroup$ But I want to plot the field in spherical coordinates: why do you convert to Cartesian coordinates? $\endgroup$ – Michael B. Heaney Feb 11 '18 at 16:32
  • $\begingroup$ When I run e[r_, [Theta]_, [CurlyPhi]_, t_] := (Sin[[Theta]]/r) [Cos[r - t] - Sin[r - t]/r] {0, 0, 1}; VectorPlot3D[ TransformedField["Spherical" -> "Cartesian", e[r, [Theta], [CurlyPhi], 1], {r, [Theta], [CurlyPhi]} -> {x, y, z}], {x, -2, 2}, {y, -2, 2}, {z, -2, 2}] it returns TransformedField::nocoord: {-1.99943,-1.99943,-1.99943} is not a non-empty list of valid variables. $\endgroup$ – Michael B. Heaney Feb 11 '18 at 16:36
  • $\begingroup$ @MichaelB.Heaney Because VectorPlot3D doesn't have a coordinate system option, as far as I can see. I am assuming that you wish to plot the field as it would appear in a 3D space, for which this works perfectly fine (though you may need to include additional boundaries or tweaking to get precisely the shape you want). Also see edit. $\endgroup$ – eyorble Feb 11 '18 at 16:37
  • $\begingroup$ OK. Why is it returning "TransformedField::nocoord: {-1.99943,-1.99943,-1.99943} is not a non-empty list of valid variables."? $\endgroup$ – Michael B. Heaney Feb 11 '18 at 16:41
  • $\begingroup$ It seems likely that you have r, theta, and phi defined, so Clear them or they will be substituted in before TransformedField can transform them. Alternatively, change their instances in the VectorPlot3D command to some consistent dummy variable names. $\endgroup$ – eyorble Feb 11 '18 at 16:44

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.