I previously wrote about typing elliptic fourier series; my Apple compiler is now capable of computing the offsets and also the relevant coefficients.
In mathematical notation:
\( a_n = \displaystyle \frac{T}{2n^2\pi^2}\sum_{p=1}^K \frac{\Delta x_p}{\Delta t_p}\left(\cos\frac{2n\pi t_p}{T} - \cos\frac{2n\pi t_{p-1}}{T}\right) \)
\( b_n = \displaystyle \frac{T}{2n^2\pi^2}\sum_{p=1}^K \frac{\Delta x_p}{\Delta t_p}\left(\sin\frac{2n\pi t_p}{T} - \sin\frac{2n\pi t_{p-1}}{T}\right) \)
\( c_n = \displaystyle \frac{T}{2n^2\pi^2}\sum_{p=1}^K \frac{\Delta y_p}{\Delta t_p}\left(\cos\frac{2n\pi t_p}{T} - \cos\frac{2n\pi t_{p-1}}{T}\right) \)
\( d_n = \displaystyle \frac{T}{2n^2\pi^2}\sum_{p=1}^K \frac{\Delta y_p}{\Delta t_p}\left(\sin\frac{2n\pi t_p}{T} - \sin\frac{2n\pi t_{p-1}}{T}\right) \)
See Kuhl and Giardnia for further details and definitions.
In Apple:
λxs.λys.λn.
{ sum ← [(+)/x]
; tieSelf ← [({.x)⊳x]; Δ ← [(-)\~(tieSelf x)]
; dxs ⟜ Δ xs; dys ⟜ Δ ys; n ⟜ ℝn
; dts ⟜ [√(x^2+y^2)]`dxs dys
; dxss ⟜ ((%)`dxs dts); dyss ⟜ ((%)`dys dts)
; pts ⟜ (+)Λₒ 0 dts
; T ⟜}. pts; k ⟜ 2*n*𝜋
; scaleRad ← [k*x%T]
; cosDiffs ⟜ (-)\~([cos.(scaleRad x)]'1 pts)
; sinDiffs ⟜ (-)\~([sin.(scaleRad x)]'1 pts)
; c ⟜ T%(2*n^2*𝜋^2)
; aₙ ← c*sum ((*)`dxss cosDiffs)
; bₙ ← c*sum ((*)`dxss sinDiffs)
; cₙ ← c*sum ((*)`dyss cosDiffs)
; dₙ ← c*sum ((*)`dyss sinDiffs)
; (aₙ,bₙ,cₙ,dₙ)
}
In places this is even clearer than the mathematical notation; (-)\~([sin.(scaleRad x)]'1 pts)
uses (-)\~
to compute successive differences of cosines all at once - compare the pointful \(\sin\frac{2n\pi t_p}{T} - \sin\frac{2n\pi t_{p-1}}{T} \). However, the mathematical typesetting is so drastically superior that the Apple code is still harder to read.