Bug introduced in 7.0, persisting through 13.2.
I am looking to plot the Magnetic Vector potential, A, as a function of position along the edge of a density plot. The density plot is fine, and I would combine the two plots using Show. After searching, I found a similar question here. I needed to modify the code a bit to get it to work in version 12.2, however the following code works just fine:
ClearAll
μ = 0.02; Px = -0.5; h = 1.0;
vData = Table[{1, j}, {j, -1, 1, 0.1}];
f[y_] := (h^2/(2 μ)) (-Px) (1 - (y/h)^2)
VectorPlot[{f[y], 0}, {x, 0, 3}, {y, -h, h}, VectorPoints -> vData,
VectorScaling -> Automatic, VectorColorFunction -> "Rainbow",
PlotRange -> {{0, 4}, {-1.1, 1.1}},
Epilog -> {{Red, Thick, Line[{{0, 1}, {4, 1}}]}, {Red, Thick,
Line[{{0, -1}, {4, -1}}]}}]
However, when I substitute my own code, with as far as I can tell the same approach, I get a "Part::partw: Part 1 of {} does not exist." error. Besides a different function form, I do not see anything different between my error prone code and the working code above. Any guidance would be much appreciated! Thanks.
ClearAll
a = 5 10^-3;
q1 = 1.602 * 10^-10;
eps0 = 8.85418781 * 10^-12;
qEnclosed[r_] := If[r < a, (q1 r^3)/a^3, q1];
eField[r_] := qEnclosed[r]/(4 π r^2 eps0);
potSphereTEMP[r_] = -Integrate[eField[r], r ];
potInfinity = Limit[potSphereTEMP[r], {r -> ∞} ];
potSphere[r_] :=
potSphereTEMP[r] -
potInfinity (* assume potential is zero at infinity *)
vData = Table[{0, j}, {j, -1.5 a, 1.5 a, 0.15 a}]
VectorPlot[{potSphere[y], 0}, {x, -a, a}, {y, -1.5 a, 1.5 a},
VectorPoints -> vData, VectorScaling -> Automatic,
VectorColorFunction -> "Rainbow",
PlotRange -> {{-a, a}, {-1.5 a, 1.5 a}}]
efield1
byefield
):VectorPlot[{potSphere[y], 0}/1, {x, -a, a}, {y, -1.5 a, 1.5 a}, VectorPoints -> vData, VectorScaling -> Automatic, VectorColorFunction -> "Rainbow", PlotRange -> {{-a, a}, {-1.5 a, 1.5 a}}]
$\endgroup$StreamPlot
is essentially the same bug, I believe: mathematica.stackexchange.com/q/133381/1871 $\endgroup$