Electromagnetic theory including Maxwell's equations, electrostatics, magnetostatics, electromagnetic waves, and radiation for physics and engineering applications.
Electromagnetic theory including Maxwell's equations, electrostatics, magnetostatics, electromagnetic waves, and radiation for physics and engineering applications.
I provide comprehensive expertise in electromagnetism, the branch of physics describing electromagnetic forces between charged particles. I enable you to apply Maxwell's equations, solve electrostatic and magnetostatic problems, analyze electromagnetic wave propagation, calculate radiation patterns, and model electromagnetic fields in materials. My knowledge spans from Coulomb's law to relativistic electrodynamics essential for electrical engineering, optics, plasma physics, and astrophysics.
When to use me
Use electromagnetism when you need to: calculate electric and magnetic fields of charge/current distributions, analyze wave propagation in various media, design antennas and waveguides, solve boundary value problems, compute electromagnetic radiation and scattering, model dielectric and magnetic materials, calculate forces and torques on charges and currents, or analyze electromagnetic compatibility.
Core Concepts
Maxwell's Equations: Four fundamental equations governing all electromagnetic phenomena (Gauss's law, Gauss's magnetism law, Faraday's law, Ampère-Maxwell law).
Electrostatics: Electric fields from stationary charges with potential energy and equipotential surfaces.
Magnetostatics: Magnetic fields from steady currents with Biot-Savart law and Ampère's law.
Electromagnetic Induction: Time-varying magnetic fields inducing electric fields (Faraday's law) with self/mutual inductance.
Electromagnetic Waves: Self-propagating solutions to Maxwell's equations traveling at speed c.
Boundary Conditions: Matching conditions for fields at interfaces between different media.
Potentials and Gauge Transformations: Scalar and vector potentials with freedom to choose gauges (Coulomb, Lorenz).
Radiation and Antennas: Time-varying currents producing propagating electromagnetic fields.
Electromagnetic Materials: Response of matter to fields (polarization, magnetization, conductivity).
Relativistic Electromagnetism: Unification with special relativity and electromagnetic field tensors.
Code Examples
Electrostatics
import numpy as np
from scipy.integrate import nquad, dblquad
from scipy.special import ellipe, ellipk
defpoint_charge_field(q, r, r0):
"""Electric field of point charge: E = kq(r-r0)/|r-r0|³"""
k = 8.99e9
r_vec = np.array(r) - np.array(r0)
r_mag = np.linalg.norm(r_vec)
if r_mag < 1e-10:
return np.zeros(3)
return k * q * r_vec / r_mag**3defline_charge_field(lambda_charge, x, L=10):
"""
Electric field of infinite line charge.
E = (2kλ)/r radially outward
"""
k = 8.99e9
r = np.abs(x)
if r < 1e-10:
return0return2 * k * lambda_charge / r * np.sign(x)
defcharged_ring_field(z, R, Q):
"""
Electric field on axis of charged ring.
E_z = kQz/(z²+R²)^(3/2)
"""
k = 8.99e9return k * Q * z / (z**2 + R**2)**1.5defcharged_disk_field(z, R, sigma):
"""
Electric field on axis of charged disk.
E_z = (2πkσ)[1 - z/√(z²+R²)]
"""
k = 8.99e9if z == 0:
* np.pi * k * sigma
* np.pi * k * sigma * ( - z / np.sqrt(z** + R**))
Q =
z =
()
()
()
z_val [, , , ]:
E = charged_ring_field(z_val, , )
()
()
z_val [, , ]:
E = charged_disk_field(z_val, , )
()
():
k =
r_vec = np.array(r) - np.array(r0)
k * q / np.linalg.norm(r_vec)
():
k =
k * p * np.cos(theta) / r**
():
epsilon_0 =
epsilon_0 * epsilon_r * A / d
():
epsilon_0 =
* np.pi * epsilon_0 * epsilon_r * L / np.log(b/a)
():
epsilon_0 =
* np.pi * epsilon_0 * epsilon_r * a * b / (b - a)
()
()
()
()
Magnetostatics
import numpy as np
from scipy.integrate import quad
defbiot_savart(I, dl, r, r0):
"""
Magnetic field from current element.
dB = (μ₀I/4π) dl × r̂/r²
"""
mu_0 = 4 * np.pi * 1e-7
r_vec = np.array(r) - np.array(r0)
r_mag = np.linalg.norm(r_vec)
r_hat = r_vec / r_mag
dl_vec = np.array(dl)
cross = np.cross(dl_vec, r_hat)
return mu_0 * I / (4 * np.pi) * cross / r_mag**2definfinite_wire_field(I, r):
"""
Magnetic field of infinite straight wire.
B = (μ₀I)/(2πr) φ̂
"""
mu_0 = 4 * np.pi * 1e-7return mu_0 * I / (2 * np.pi * np.abs(r))
defcircular_loop_field(z, R, I):
"""
Magnetic field on axis of circular loop.
B_z = (μ₀I R²)/(2(R²+z²)^(3/2))
"""
mu_0 = 4 * np.pi * 1e-7return mu_0 * I * R**2 / (2 * (R**2 + z**2)**1.5)
defsolenoid_field(n, I, L, z):
"""
Magnetic field of ideal solenoid.
B = μ₀nI (inside), 0 (outside)
"""
mu_0 = 4 * np.pi * 1e-7
n_density = n / L
return mu_0 * n_density * I
print("Magnetostatic fields:")
print()
()
()
():
mu_0 = * np.pi *
mu_0 * I / ( * np.pi) * np.log(r)
():
mu_0 = * np.pi *
mu_0 * I * R / ( * np.pi)
():
mu_0 = * np.pi *
mu_0 * n** * A / L
():
mu_0 = * np.pi *
mu_0 * mu_r * N** * a / b * np.log(b/a)
():
mu_0 = * np.pi *
mu_0 / np.pi * (np.log(d/a) - )
()
A = np.pi * ()**
()
():
mu_0 = * np.pi *
mu_0 * I1 * I2 / ( * np.pi * d) * L
I1, I2 = ,
d =
L =
()
()
Electromagnetic Waves
import numpy as np
defwave_speed(epsilon, mu):
"""Speed of EM wave in medium: v = 1/√(εμ)"""
epsilon_0 = 8.85e-12
mu_0 = 4 * np.pi * 1e-7return1 / np.sqrt(epsilon * epsilon_0 * mu * mu_0)
defwave_impedance(epsilon, mu):
"""Intrinsic impedance: η = √(μ/ε)"""
eta_0 = 377# Ohms (free space)return eta_0 * np.sqrt(mu / epsilon)
defskin_depth(frequency, conductivity, permeability):
"""δ = √(2/(ωμσ))"""
mu_0 = 4 * np.pi * 1e-7
omega = 2 * np.pi * frequency
return np.sqrt(2 / (omega * mu * conductivity))
# Wave propagation in media
c = 3e8# Speed of lightprint("EM wave propagation:")
print(f" Free space: v = {c:.2e} m/s, η = 377 Ω")
# In dielectric (εᵣ = 4)
v_dielectric = c / 2
eta_dielectric = 377 / 2print(f" Dielectric (εᵣ=4): v = {v_dielectric:.2e} m/s, η = {eta_dielectric:.1f} Ω")
# In conductor (copper at 1 MHz)
sigma_copper = 5.8e7
mu_r_copper =
f =
delta = np.sqrt( / ( * np.pi * f * mu_0 * sigma_copper))
()
():
E0 * np.cos(k * z - omega * t)
():
E0 / c * np.cos(k * z - omega * t)
():
mu_0 = * np.pi *
np.cross(E, B) / mu_0
():
E0** / ( * eta)
()
E0 =
()
():
(n2 - n1) / (n2 + n1)
():
* n1 / (n2 + n1)
n_air, n_glass = ,
R = fresnel_reflection(n_air, n_glass, )
T = fresnel_transmission(n_air, n_glass, )
()
()
()
Radiation
import numpy as np
defhertzian_dipole_radiation(I, L, theta, frequency):
"""
Radiation from short dipole antenna.
Far field: E_θ = (jωμ₀I₀L sinθ)/(4πr) e^(-jkr)
"""
mu_0 = 4 * np.pi * 1e-7
omega = 2 * np.pi * frequency
k = omega / c
E = omega * mu_0 * I * L * np.sin(theta) / (4 * np.pi * r)
return E
defdipole_radiated_power(I, L, frequency):
"""
Total radiated power from Hertzian dipole.
P = (μ₀ω²I₀²L²)/(12πc)
"""
mu_0 = 4 * np.pi * 1e-7
omega = 2 * np.pi * frequency
return mu_0 * omega**2 * I**2 * L**2 / (12 * np.pi * c)
defantenna_directivity(radiation_pattern):
"""D = 4π⟨P⟩/P_max"""passdefhalf_wave_dipole_radiation(theta):
"""Radiation pattern of half-wave dipole."""return np.cos(np.pi/2 * np.cos(theta)) / np.sin(theta)
defeffective_aperture(D, wavelength):
"""A_eff = Dλ²/(4π)"""return D * wavelength**2 / (4 * np.pi)
# Calculate radiated power
I = 1# A
L = 0.01
f =
P_rad = dipole_radiated_power(I, L, f)
()
()
()
lambda_dipole = c / f
L_hw = lambda_dipole /
():
* I_rms**
()
()
()
()
():
c =
intensity / c * ( + reflectivity)
I_sun =
P_sun_earth = radiation_pressure(I_sun, )
()
()
()
Best Practices
Always verify Gauss's law and Ampère's law numerically for symmetric charge/current distributions.
Use appropriate boundary conditions (continuity of tangential E and H, normal D and B) when solving interface problems.
For time-harmonic fields, work with complex amplitudes and use phasor notation consistently.
In numerical EM, ensure grid resolution is fine enough to resolve skin depth and wavelength features.
Use the method of images for solving boundary problems with conductors and dielectrics.
Apply gauge transformations carefully to ensure scalar and vector potentials satisfy the Lorenz gauge.
For radiation calculations, distinguish between near-field (inductive/capacitive) and far-field (radiative) regions.
When computing self-inductance, account for both internal and external flux linkages.
For antenna design, ensure proper matching to maximize power transfer and radiation efficiency.
Consider dispersion in wave propagation by using frequency-dependent material properties when needed.
return
2
return
2
1
2
2
# Example calculations
1e-9
# 1 nC
0.1
# 10 cm from charge
print
"Point charge field:"
print
f" E at z=0.1m from q=1nC: {point_charge_field(Q, [z, 0, 0], [0, 0, 0])[0]:.2e} V/m"
print
f"\nCharged ring (R=0.1m, Q=1μC):"
for
in
0.05
0.1
0.2
0.5
0.1
1e-6
print
f" E(z={z_val}m) = {E:.2e} V/m"
print
f"\nCharged disk (R=0.1m, σ=1e-5 C/m²):"
for
in
0.01
0.05
0.1
0.1
1e-5
print
f" E(z={z_val}m) = {E:.2e} V/m"
# Electric potential
def
point_charge_potential
q, r, r0
"""V = kq/|r-r0|"""
8.99e9
return
def
dipole_potential
p, r, theta
"""
Potential of electric dipole.
V = kp·r̂/r² = kp cos(θ)/r²
"""