This is a function that takes a function, turn it into a vector, then plots the vector and its contour.
plot[ϕ_] :=
Module[{Efield = -{D[ϕ, x], D[ϕ, y]}, plot1, plot2},
plot1 = ContourPlot[ϕ, {x, -2, 2}, {y, -2, 2},
ContourShading -> False, DisplayFunction -> Identity];
plot2 = VectorPlot[Efield, {x, -2, 2}, {y, -2, 2},
VectorScale -> Small, DisplayFunction -> Identity];
Show[plot1, plot2, DisplayFunction -> $DisplayFunction]]
ϕ = 1/Sqrt[x^2 + (y - 0.5)^2] - 1/Sqrt[x^2 + (y + 0.5)^2];
plot[ϕ]
This is my output:
However the plot supposed to look like this:
Why is my output so different and how can I fix it?
I have been studying notes from an undergrad course that used Mathematica 5, so my knowledge of it is rather outdated.
StreamPlot
instead ofVectorPlot
However, it seems unlikely that you get the desired plot since you have maxima in the places that vectorplot correctly shows but your "supposed" plot omits. $\endgroup$VectorPlot
for this problem? $\endgroup$