title: Mathematica implementation of Biot-Savart law for a current-carrying wire segment
body: <p>I'm trying to visualize the magnetic field around a short, linear, current-carrying wire segment.</p>
  
  <p>The code that I have seems to be not working but I can't figure out why, </p>
  
  <pre><code>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 -&gt; False, 
     Axes -&gt; False],
    Graphics3D[{Red, Line[{p1, p2}],}],
    Boxed -&gt; False,
    Axes -&gt; False,
    SphericalRegion -&gt; True,
    PlotRange -&gt; ({
       {-4`, 4`},
       {-4`, 4`},
       {-4`, 4`}
      }),
    Lighting -&gt; "Neutral"]
   ]
  </code></pre>
  
  <p>Is this not working because the field goes to infinity as R->0, or some other reason? Is there a workaround? </p>
  
  <p>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? </p>
  
  <p>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.</p>
  
  <p>Thanks in advance,
  Ben</p>