Electric and magnetic fields in various static situations
Calculating the field via the potentials (calculate $\phi$ then $\vec E=-\nabla\phi$)
We can define the spherical polar coordinate system $(r',\theta',\phi')$ such that the angles $\theta'$ and $\phi'$ are measured relative to the vector $\vec r$, that is, the north pole is chosen to be in the direction of $\vec r$.
$$ \begin{aligned} \phi(r)&=\frac{1}{4\pi\epsilon_0}\int^\infin_0r'^2\,\text dr \int^\pi_0 \sin\theta'\,\text d\theta' \int^{2\pi}_0\text d\phi'\frac{\rho(r')}{(r^2+r'^2-2rr'\cos\theta')^\frac 12} \\ &=\frac{1}{4\pi \epsilon_0}2\pi \int^\infin_0 \vec r'^2\text dr' \int^\pi_0\sin\theta'\text \,d\theta'\frac{\rho(r')}{(r^2+r'^2-2rr'\cos\theta')^\frac 12} \\ &=\frac{1}{2\epsilon_0}\int^\infin_0 r'^2\, \text dr'\,\,\rho(r')\left [ \frac{(r^2+r'^2-2rr'\cos\theta')^\frac 12}{rr'}\right ] \\ &=\frac{1}{2\epsilon_0 r}\int^\infin_0 \text dr' \,r'\,\rho(r')(r+r'-|r-r'|)\\ &=\frac{1}{\epsilon_0}\left [ \frac 1r \int^r_0 \text dr'\, r'^2\, \rho(r')+\int^\infin_r\text dr'\,r'\,\rho(r')\right ] \end{aligned} $$
The electric field is given by
$$ \vec E=-\nabla \phi = -\frac{\partial \phi}{\partial r}\hat r=\left ( \frac{1}{\epsilon_0 r^2}\int^r_0\text dr' \,r'^2 \rho(r') \right )\hat r $$
Calculating the field via Gauss’ law.
We can deduce that $\vec E=E_r\hat r$, then we choose a spherical surface with radius $r$
$$ \int\vec E\cdot \text d\vec S=4\pi r^2 E_r= \frac{Q(r)}{\epsilon_0}=\frac{4\pi}{\epsilon_0}\int^r_0\,\text dr'\,r'^2\,\rho(r') $$
Where $Q(r)$ is the charge inside a sphere or radius $r$ therefore
$$ E_r=\frac{1}{\epsilon_0 r^2}\int^r_0\text dr'\,r'^2\,\rho(r') $$
Magnetic field generated by a wire in $\hat z$ carrying current $I$. The wire is infinitely long
Using Biot-Savart law
we define $\vec r=(x,y,z)$ which is the location at which we want to find the value. We have a position vector inside the current distribution
$$ \vec r'=(0,0,z') \qquad \text d\vec l=(0,0,1)\,\text dz' $$
where $-\infin< z'<+\infin$. The Biot-Savart law for this geometry becomes
$$ \begin{aligned} \vec B(\vec r)&=\frac{\mu_0 I}{4\pi} \int\frac{(0,0,1)\text dz'\times (x,y,z-z')}{(x^2+y^2+(z-z')^2)^\frac 32} \\ &=\frac{\mu_0 I}{4\pi}(-y,x,0) \int^\infin_{-\infin}\frac{\text dz'}{(x^2+y^2+(z-z')^2)^\frac 32}
\end{aligned} $$
In order to solve this integral we make the substitutions
$$ \frac{z-z'}{\sqrt{x^2+y^2}}=\tan(\alpha) \qquad \Leftrightarrow \qquad \frac{-\text dz'}{\sqrt{x^2+y^2}}=\sec^2(\alpha) \,\text d\alpha $$
Hence
$$ \vec B(\vec r)=\frac{\mu_0 I}{4\pi}\frac{(-y,x,0)}{x^2+y^2}\int^{\pi/2}_{-\pi/2}\cos(\alpha)\,\text d\alpha $$
We can integrate
$$ \vec B(\vec r)=\frac{\mu_0I}{2\pi}\frac{(-y,x,0)}{x^2+y^2} $$
We notice the azimuthal unit vector $\hat \theta=(-y/r,x/r,0)=(-\sin\theta,\cos\theta,0)$
$$ \vec B(\vec r)=\frac{\mu_0 I}{2\pi r}\hat \theta $$
We try with Ampere’s law
We use $\vec B=B_\theta\hat\theta$. We chose a circle around the wire of radius $r$
$$ \int\vec B\cdot \text d\vec l=B_\theta 2\pi r=\mu_0 I $$
Therefore via Ampere’s law around a the current is in obvious agreement with the magnetic field calculated via the Biot-Savart law
Consider a charge circular loop of radius $R$ and char per unit length $\lambda$ on the $x$-$y$ plane and centered at the origin. We cant use Gauss’ law because there is no symmetry.
Adopting a cylindrical polar coordinate system, the charge density $\rho(\vec r')$ is zero except when $r'=R$ and $z'=0$ and therefore it is given by
$$ \rho(r',\theta',z')=\lambda \delta(r'-R)\delta (z') $$
We can use a cartesian coordinate for $\vec r=(x,y,z)$ and a cylindrical coordinate system for $\vec r'=(r'\cos\theta',r'\sin\theta',z')$ and hence
$$ |\vec r-\vec r'|^2 = x^2+y^2+r'^2-2xr'\cos\theta'-2yr'\sin\theta'+(z-z')^2 $$
Therefore the electric field is
$$ \begin{aligned} \vec E(x,y,z)=&\frac{1}{4\pi\epsilon_0}\int^\infin_{-\infin}\text dz'\int^\infin_0 r'\,\text dr'\int^{2\pi}_{0}\text d\theta' \\ &\times \frac{\lambda\delta(r'-R)\delta(z')}{[F(x,y,z,r',\theta',z')]^3} \begin{pmatrix} x-r'\cos\theta' \\ y-r'\sin\theta' \\ z-z' \end{pmatrix} \end{aligned} $$
where $F(x,y,z,r',\theta',z')=(x^2+y^2+r'^2-2xr'\cos\theta'-2yr'\sin\theta'+(z-z')^2)^\frac 12$
The $r'$ and $z'$ integrations can be performed using the properties of the $\delta$-function
$$ \vec E(x,y,z)=\frac{\lambda R}{4\pi \epsilon_0}\int^{2\pi}_0\text d\theta' \frac{1}{[F(x,y,z,R,\theta',0)]^3}\begin{pmatrix} x-R\cos\theta' \\ y-R\sin\theta' \\ z \end{pmatrix} $$
This integral is difficult to compute, it can be down for points on the axis of the loop where $x=y=0$ for which we obtain
$$ \vec E(x,y,z)=\frac{\lambda Rz}{2\epsilon_0 (R^2+z^2)^\frac 32}\begin{pmatrix} 0 \\ 0 \\ 1 \end{pmatrix} $$
🌴 Consider the electrostatic potential and electric field at some point $\vec r$ which is a long way away from some localized distribution of charge.
This implies that $|\vec r-\vec r'| \approx \vec r$ where $\vec r'$ is a coordinate inside the charge distribution
$$ \begin{aligned} \phi(\vec r)&=\frac{1}{4\pi \epsilon_0} \int \text dV'\frac{\rho(\vec r')}{|\vec r-\vec r'|~}\approx \frac{1}{4\pi \epsilon_0 r} \int\text dV'\rho(\vec r')=\frac{Q}{4\pi \epsilon_0 r} \\ \vec E(\vec r)&= \frac{1}{4\pi\epsilon_0}\int\text dV' \frac{(\vec r-\vec r')\rho(\vec r')}{|\vec r-\vec r'|^3}\approx \frac{1}{4\pi\epsilon_0}\frac{\vec r}{r^3}\int\text dV'\rho(\vec r')=\frac{Q}{4\pi\epsilon_0 r^2}\hat r
\end{aligned} $$
🗒️ Note: at far distances the potential field due to an extended but localized charge distribution looks like the potential field of a point particle whose charge is the integrated charge density $Q=\int\text dV \rho(\vec r)$