Mathematica implementation of Biot-Savart law for a current-carrying wire segment
I'm trying to visualize the magnetic field around a short, linear, current-carrying wire segment.
开发者_JS百科The code that I have seems to be not working but I can't figure out why,
p1 = {0, 0, 0};
p2 = {0, 0, 1};
p12 = p2 - p1;
Subscript[\[Mu], 0] = 4 Pi*10^(-7);
l[s_] := (1 - s) p1 + s p2;
R = {x, y, z} - l[s];
r = R/Sqrt[R.R];
B = Subscript[\[Mu], 0]/(4 Pi)
Integrate[l[s]\[Cross]r/(R.R), {s, 0, 1}];
Manipulate[
Show[
VectorPlot3D[B, {x, -4, 4}, {y, -4, 4}, {z, -4, 4}, Boxed -> False,
Axes -> False],
Graphics3D[{Red, Line[{p1, p2}],}],
Boxed -> False,
Axes -> False,
SphericalRegion -> True,
PlotRange -> ({
{-4`, 4`},
{-4`, 4`},
{-4`, 4`}
}),
Lighting -> "Neutral"]
]
Is this not working because the field goes to infinity as R->0, or some other reason? Is there a workaround?
Also, assuming I get the expression for the magnetic field right, are there any other cool ways to visualize the magnetic field, e.g. like an antenna pattern?
Any help would be greatly appreciated, I'm trying to teach myself Mathematica from the Demo Project and from a textbook, and it's going slowly.
Thanks in advance, Ben
Integrate is taking a lot of time. Minimally changing this in order to produce something, you can add GenerateConditions->False
, like so:
B = Subscript[\[Mu], 0]/(4 Pi)*
Integrate[(l[s]\[Cross]r/(R.R)), {s, 0, 1},
GenerateConditions -> False];
which does work. The rest of your code seems a bit random, have you added things in an effort to troubleshoot and left them in, or do you need help with that too?
精彩评论