1
$\begingroup$

as part of my electromagnetic waves course I want to plot all of the fields in order to better understand the material, but I ran into a few problems in the process. for example:

f1[x] = x^2
f2[y] = -y^2
Coulomb = {x^2, -y^2, 0}
Plot3D[x^2 - y^2, {x, -4, 4}, {y, -4, 4}]
VectorPlot[{x^2, -y^2}, {x, -3, 3}, {y, -3, 3}, PlotLegends -> Automatic]
VectorPlot3D[Evaluate[Coulomb],{x,-1,1},{y,-1,1},{z,-1,1}, VectorPoints -> Coarse, VectorScale -> Medium, 
 VectorStyle -> "LeftArrow3D"]

ECoulomb2 = {$\frac{qd*Cos[\Theta]}{2 \Pi r^3}$, $\frac{qd*Sin[\Theta]}{4 \Pi r^3}$, 0}

Ecartesian2 = TransformedField["Spherical" -> "Cartesian", Ecoulomb2, {r,$\Theta$,$\Phi$} -> {x,y,z}]

all runs smoothly and I'm getting the desired outputs. but when I try to create the following outputs I get empty graphs on the other end:

SliceContourPlot3D[Ecartesian2,"CenterPlanes", {x, -2, 2}, {y, -2, 2}, {z, -2, 2}]
VectorPlot[Ecartesian2, {x,-3,3}, {y,-3,3}, PlotLegends -> Automatic]
VectorPlot3D[Evaluate[Ecartesian2], {x,-1,1}, {y,-1,1}, {z,-1,1}, VectorPoints -> Coarse, 
 VectorScale -> Medium, VectorStyle -> "LeftArrow3D"]

I tried to leave ECoulomb2 in {r,$\Theta$,$\Phi$} coordinates and plot it in a 2 variable plain, depending only on r and $\Theta$ but still getting an empty graph.

what will be the difference between plotting it in {r,$\Theta$,$\Phi$} and {x,y,z} coordinates?

I know the output supposed to looks something like this: r,Theta dependence

$\endgroup$
1
$\begingroup$

Make sure you write out your input properly. You're using capital Pi $\Pi$ not lowercase $\pi$ i.e 3.1415... so this should be:

ECoulomb2 = {q*d*Cos[Θ] 2 π r^3, q*d*Sin[Θ] 4 π r^3, 0};

And in your conversion you made a typo: Ecoulomb2 should be ECoulomb2.

The plots will still not work because you didn't provide values for d or q, but if I give these values of 1, then I get the VectorPlot3D working.

The 2D VectorPlot doesn't work however and will be all white because your Ecartesian2 has three coordinates in a 2D plot, and you're also plotting the wrong coordinates. Try this instead:

q = 1;
d = 1;

ECoulomb2 = {q*d*Cos[Θ] 2 π r^3, q*d*Sin[Θ] 4 π r^3, 0};

Ecartesian2 = 
 TransformedField["Spherical" -> "Cartesian", ECoulomb2, {r, Θ, Φ} -> {x, y, z}]

(* here I'm taking the x,z coordinates {1,3} only and setting y to 0.25 *)
VectorPlot[Ecartesian2[[{1, 3}]] /. y -> 0.25, {x, -3, 3}, {z, -3, 3},
  PlotLegends -> Automatic]

VectorPlot3D[
 Evaluate[Ecartesian2], {x, -1, 1}, {y, -1, 1}, {z, -1, 1}, 
 VectorPoints -> Coarse, VectorScale -> Medium, 
 VectorStyle -> "LeftArrow3D"]

field lines

$\endgroup$
4
  • $\begingroup$ now it works flawlessly, thank you.. why do I have to fix a point in space with VectorPlot[Ecartesian2[[{1, 3}]] /. y -> 0.25, {x, -3, 3}, {z, -3, 3}, PlotLegends -> Automatic]? what if I want a more general plot for the given field? $\endgroup$ – bitmetvt Mar 28 at 15:57
  • $\begingroup$ will the plot look any different if we'll choose to plot it under any other coordinate system? ( which I still don't understand how to do even though I have read the documentation thoroughly) $\endgroup$ – bitmetvt Mar 28 at 16:01
  • $\begingroup$ Can you explain to me please how can I plot it under spherical coordinates for instance? $\endgroup$ – bitmetvt Mar 28 at 16:03
  • $\begingroup$ You have to fix the y, somewhere because otherwise it's an unbound variable in the vector plot - it's not a number, just a symbol, which cannot be plot into arrows. For spherical vector plots, search this site - there aren't convenient builtin functions that I'm aware of. $\endgroup$ – flinty Mar 28 at 16:18

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.