# Biot-Savart Integral

I want to calculate the magnetic field of a finite wire of current along the z axis. I assume a frame of reference like the one in Fig. below:

It is a classical problem with a well known solution for B:

I want to apply the Biot-Savart law, which in integral form is:

So my code is the following:

(*p1 and p2 are the extremes of the current wire of length h*)

p1 = {0, 0, -1/2}*h/2;
p2 = {0, 0, +1/2}*h/2;

(*d[s] represents the path from p1 to p2*)

d[s_] := (1 - s) p1 + s p2;

(*The final point at which I want to calculate the field. It is on \
the xy plane at a distance r from the current wire*)

FP = {x, Sqrt[r^2 - x^2], 0};
R = FP - d[s];

(*The unit vector from R*)

ar = R/Sqrt[R.R];

(*How I write the Biot-Savart law. GenerateConditions\[Rule] False \
speeds up, I think, the Integrate routine*)

{Bx, By, Bz} = μ0/(4 π)*
Integrate[d[s]\[Cross]ar/(R.R), {s, 0, 1},
GenerateConditions -> False] 

The result, when the z coordinate of the FP is 0, is always {0,0,0}. What I think I should have is the expression reported above for B



If I let in FP the z coordinate free to take any z value, I have {Bx, By, 0}, which makes sense. However, B=Sqrt[Bx^2+By^2] is not even close to the reported expression. Can anyone tell me what I am doing wrong?

First change p1,p2 to get a wire of length h:

p1 = {0, 0, -1 }*h/2;
p2 = {0, 0, +1 }*h/2;
Sqrt[(p1 - p2) . (p1 - p2)]
(* Sqrt[h^2]*)


Integrand has to be modified:

{Bx, By, Bz} = μ0/(4 π)*Integrate[Cross[D[d[s], s], ar]/(R . R),{s,0,1},Assumptions -> {h > 0, r > 0}]

Sqrt[# . #] &[{Bx, By, Bz}] //FullSimplify[#, {h > 0, r > 0, μ0 > 0}]&
(*(h μ0)/(2 π r Sqrt[h^2 + 4 r^2])*)

• Thanks a lot @Ulrich Neumann. But I do not see in your last expression the value h at the numerator. It should be Sqrt[h^2μ0^2/(r^2 (h^2 + 4 r^2))]/(2 π). Also I do not understand the line: Assumptions -> {h > 0, r > 0}. I've tried to run your code without those assumptions and it still returns the result you report (which is still missing the value h at the numerator). Thanks a lot! Commented Nov 15, 2021 at 16:44
• It turns out the expected result if you use Cross[{0, 0, h}, ar]/(R . R), but I am not sure at all. Commented Nov 15, 2021 at 16:56
• Yes, see my modified answer. Vector {0,0,h}== D[d[s], s]` Commented Nov 15, 2021 at 17:10
• Thanks very much! So If I define a curved path to go from p1 to p2 (it could be a portion of a saddle coil for example which I am interested in), can I in principle calculate the resulting field at any point with the integrand you report Cross[D[d[s], s], ar]/(R . R) ?? Commented Nov 15, 2021 at 17:21
• You're welcome. Yes I think so Commented Nov 15, 2021 at 17:31