1
$\begingroup$

so I'm new to Mathematica but kind of fail to find the proper function. I read the documentation forr quite some time now.

So I have an electric field and it's potential and I'd like to plot both of them.

$\vec{E}(x,y,z)=\begin{pmatrix}x^2+z\\y\\x\end{pmatrix}$

$\phi = -\frac{1}{3}x^3-xz-\frac{1}{2}y^2$

With $\vec{E}=-\nabla \phi$

What I did in mathematica:

VectorPlot3D[{x^2 + z, y, x}, {x, -5, 5}, {y, -5, 5}, {z, -5, 5}, VectorScale -> small, PlotTheme -> "Marketing"]

That looks quiet okay - I think thats right. But I have no idea how to Plot the potential properly. Can anyone help me here please? :)

$\endgroup$
  • $\begingroup$ $\phi$ is a function of 3 variables; please specify how do you want it to be plotted, e.g. a slice or sth else. $\endgroup$ – corey979 Oct 21 '16 at 13:36
6
$\begingroup$

It really depends on what your purpose is. Here are a few built-in options for visualizing such a function - you should read the docs for each to see what options are available.

You can make a 3D Image which is best for gaining intuition, or qualitative information in cases like these.

phi[x_,y_,z_]:=-1/3*x^3-x*z-1/2*y^2;
samples=Range[-5,5,0.1];
img3d = Image3D[Table[phi[x,y,z],{x,samples},{y,samples},{z,samples}]]

enter image description here

Or:

GraphicsGrid@Partition[Image3DSlices@img3d,4]

To see the slices from the 3D image

enter image description here

Or you can make a 3D slice contour plot:

SliceContourPlot3D[
 phi[x, y, z], {x, -5, 5}, {y, -5, 5}, {z, -5, 5}
 , Contours -> 10
 ]

Which I find hard to interpret

enter image description here

Or you can look at individual contour plots in 2D for a fixed plane e.g. z=0:

ContourPlot[phi[x, y, 0], {x, -5, 5}, {y, -5, 5}]

enter image description here

As Simon Woods points out, I forgot the most obvious answer, ContourPlot3D:

ContourPlot3D[
 phi[x, y, z], {x, -5, 5}, {y, -5, 5}, {z, -5, 5}
 , Contours -> 10
 ]

enter image description here

$\endgroup$
  • 1
    $\begingroup$ I think ContourPlot3D would be a good addition to this answer $\endgroup$ – Simon Woods Oct 21 '16 at 19:19
  • $\begingroup$ @Simon Woods, I knew I forgot something. Thanks! $\endgroup$ – N.J.Evans Oct 21 '16 at 20:23
  • $\begingroup$ Thanks - I'll look into it and respond later properly. $\endgroup$ – xotix Oct 28 '16 at 9:56

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.