This repo contains two examples of calculating electric fields by numerical integration.
We're interested in the axial electric field of a charged disk lying in the x-y plane. The disk has a radius R and is centred at the origin. To calculate the electric field we first construct the contribution to the field at a position z by a disk element dQ at a radius r < R. Note that any planar contributions to the field are cancelled out by another charge element 180 degrees away from dQ. This implies that the electric field is only song the z-axis. Now we have
where
If we assume the disk has a charge Q smeared over the surface then we have
in polar co-ordinates. Integrating this across the angular domain we have
To integrate this on python we will first make it dimensionless:
where
This integral can be done analytically, and the resulting function agrees with the numerical simulation.
The goal is to calculate the planar electric field of a charged loop lying in the x-y plane. The loop has a radius R and is centred at the origin. To calculate the electric field we first construct the azimuthal contribution to the field at a position (r, theta) by a loop element dQ at (R, alpha):
It is worth to note that this is an integral of a periodic function with odd symmetry. As a result, the integral vanishes over any interval with length . Now we can construct the radial contribution to the field at a position (r, theta) by dQ:
This is an elliptic integral that cannot be expressed as a combination of simple functions. We will now simplfy and remove units:
This expression will be numerically integrated to obtain the field. Note that the results agree with physical intuition.