Magnetic field due to a finite-length straight wire carrying a constant current My question: I want to find an expression at any point in space for the magnetic field $\mathbf B$ produced by a straight wire of finite length $L$ carrying a constant current $I$.
I think that we can simplify our analysis by using cylindrical coordinates, and by placing the wire along the $z$ axis such that the center of the wire is at the origin; we assume the current flows in the positive $z$ direction. So the diagram would be the following:


My attempt: Below I show my procedure which I initially wrote in Microsoft Word. I think it'd be a waste of time to translate it to Latex, but if you ask for it, I'll do it.
Image 1/4:

Image 2/4:

Image 3/4:

Image 4/4:

End of the computations.
Here's a plot in Wolfram Mathematica assuming $I = 10 \text{ A}$ and $L = 10 \text{ m}$:

Now, there are some reasons why I think my formula for $\mathbf B$ could be correct:

*

*The magnitude of the field is inversely proportional to the perpendicular distance $\rho_0$ between the wire and the point $P$. So the farther the point is from the wire, the weaker the field, as expected.

*The direction of the field is in accordance with the right-hand rule.

*In the extreme/particular case of an infinite wire, the formula simplifies to the well-known formula obtained from Ampère's law (in magnetostatics i.e. without Maxwell's correction).

However, I'm a bit hesitant because I haven't touched vector calculus nor electromagnetic theory since I took a class about 1.5 years ago; I had to review many mathematical equations to answer this question. So I'm asking you to check my work to see if there're no mistakes.
By the way, I'd be more grateful if you could manage to simplify the general expression I got.
 A: Your answer is correct, and it can be arrived at more easily. Consider a finite line current on the $x$-axis, and an observation point which is parallel to the $x$-axis offset at $d_0 \hat z$. (In the image below, it is shown on the $z$-axis.)

We have $\mathbf r = x \hat x  + d_0 \hat z$ as the observation point, and $\mathbf r' = x' \hat x$ as the source point. The Biot-Savart law gives
$$
\mathbf B(\mathbf r) = \frac{\mu I}{4\pi} \int_{-a}^{a} \frac{d\mathbf s' \times (\mathbf r - \mathbf r')}{|\mathbf r - \mathbf r'|^3} \\[2em]
= \frac{\mu I}{4\pi} \int_{-a}^{a} \frac{\sin \theta\ d x'}{|\mathbf r - \mathbf r'|^2}
$$
Where $\theta$ is the angle between the current direction $\hat s = \hat x$ and the displacement vector $|\mathbf r - \mathbf r'|$. This is derived using the fact that $\mathbf a \times \mathbf b = |a||b|\sin \theta$. You can confirm that the angle $\theta$ here is the same as that shown in the diagram.
Expand the denominator in the integrand,
$$
\frac{\sin \theta}{(x'-x)^2+d_0^2}
$$
And note from the diagram above that for angle $\phi$ as shown, $\sin \theta = \cos \phi = \frac{d_0}{(x'-x)^2+d_0^2}$. Our integral would be simpler if we integrate over the angle $\phi$ instead of the rectilinear $x'$, and we can do this using e.g.
$$
\phi = \arctan \left(\frac{x'-x}{y_0}\right)
$$
(again seen directly from the image of the triangle above), and the differential becomes
$$
dx' = d\phi \frac{1}{d_0} ((x'-x)^2+y_0^2)
$$
Which cancels out in the original integral, making it, after substitution,
$$
|\mathbf B| = \frac{\mu I}{4\pi d_0} \int_{\phi_1}^{\phi_2} \cos \phi d\phi = \frac{\mu I}{4\pi d_0} (\sin \phi_2 - \sin \phi_1)
$$
Where $\phi_1$ is the angle made when $x'=-L/2$, and $\phi_2$ is the angle made when $x'=+L/2$, for a given value of $x$. We have then
$$
\sin \phi_2 - \sin \phi_1 = \frac{a-x}{\sqrt{(a-x)^2+d_0^2}} + \frac{a+x}{\sqrt{(a+x)^2+d_0^2}}
$$
Where $a=L/2$. And therefore the magnitude of the magnetic field is
$$
|\mathbf B| = \frac{\mu I}{4\pi d_0} \left(\frac{a-x}{\sqrt{(a-x)^2+d_0^2}} + \frac{a+x}{\sqrt{(a+x)^2+d_0^2}}\right)
$$
The direction $\hat B$ is always in the same direction when parallel to the current-carrying wire, as it is the mutual perpendicular of the displacement vector and the direction of current flow. Thus it obeys the right-hand rule for all $x$, and $\hat H = -\hat y$.
This is the same result as you obtained, but for a current along the $x$-axis, making the transformations $\rho_0 \rightarrow d_0, L/2 \rightarrow a, z_0 \rightarrow x$, and using a cylindrical unit vector $\hat \phi$.
Needless to say, this expression is not physically meaningful on its own, but it can be used for superposition.
