feat(decart): interp
This commit is contained in:
parent
1bd9143186
commit
19557f3a62
14 changed files with 681 additions and 208 deletions
|
|
@ -1,31 +1,8 @@
|
|||
package numerics
|
||||
|
||||
// Field returns the time derivative of a geographic state at (t, y).
|
||||
// The derivative is direction-independent; the integrator applies the sign
|
||||
// of dt for reverse-time integration.
|
||||
type Field func(t float64, y GeoVec) GeoVec
|
||||
|
||||
// Crossed reports whether a termination condition holds at (t, y).
|
||||
type Crossed func(t float64, y GeoVec) bool
|
||||
|
||||
// RK4Step performs one classical Runge-Kutta-4 step from (t, y) with step dt.
|
||||
// dt may be negative to integrate backwards in time. Longitude wrapping is
|
||||
// applied at every intermediate add via GeoAdd, matching the reference
|
||||
// integrator. The function performs no heap allocation.
|
||||
func RK4Step(t float64, y GeoVec, dt float64, f Field) GeoVec {
|
||||
half := dt / 2
|
||||
k1 := f(t, y)
|
||||
k2 := f(t+half, GeoAdd(y, half, k1))
|
||||
k3 := f(t+half, GeoAdd(y, half, k2))
|
||||
k4 := f(t+dt, GeoAdd(y, dt, k3))
|
||||
|
||||
y2 := GeoAdd(y, dt/6, k1)
|
||||
y2 = GeoAdd(y2, dt/3, k2)
|
||||
y2 = GeoAdd(y2, dt/3, k3)
|
||||
y2 = GeoAdd(y2, dt/6, k4)
|
||||
return y2
|
||||
}
|
||||
|
||||
// RefineCrossing locates a crossing between (t1, y1) (not crossed) and
|
||||
// (t2, y2) (crossed) by binary search in the linear-interpolation parameter
|
||||
// space, stopping when the parameter interval is narrower than tol.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue