A bar magnet is modelled with two equal and opposite magnetic poles ±q separated by its length L (the "Gilbert" picture). Each pole produces a Coulomb-like field and the fields superpose with the uniform Earth field BE.
B(r) = (μ0/4π) q (r − rpole) / |r − rpole|³, q = m / L Far away: Baxis = (μ0/4π) 2m / r³, Bequator = (μ0/4π) m / r³ Compass needle: I θ̈ = −μB sin(θ − θB) − γ θ̇, T = 2π √(I / μB)Field lines are traced by stepping along B/|B| with a second-order midpoint method. The four checks compare the exact two-pole axis field with the point-dipole formula, test the axis/equator ratio of 2, count how many lines starting on the N pole terminate on the S pole (all of them, since total pole strength is zero), and compare an integrated needle oscillation period with the small-angle formula.
Simplifications: the field is evaluated in the plane through the magnet axis; real magnets have internal field and finite thickness; needles are non-interacting; the Earth field is uniform and horizontal; the needle damping is fixed. Magnet moment values are typical, not specific to any product.