MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ lorenz_attractor()

MAYAFLUX_API double MayaFlux::Kinesis::Discrete::lorenz_attractor ( std::span< const double >  window,
std::span< double >  coefs 
)
noexcept

Lorenz system stepped once by fourth order Runge-Kutta, returning x.

The state and parameters live in the array, so editing sigma, rho, beta or dt between calls sweeps the system through its regimes. An array shorter than seven gives zero.

Definition at line 586 of file Kernels.cpp.

587{
588 if (coefs.size() < 7)
589 return 0.0;
590
591 const double sigma = coefs[0];
592 const double rho = coefs[1];
593 const double beta = coefs[2];
594 const double dt = coefs[3];
595
596 using Vec = std::array<double, 3>;
597 const auto derivative = [sigma, rho, beta](const Vec& p) -> Vec {
598 return { sigma * (p[1] - p[0]), p[0] * (rho - p[2]) - p[1], p[0] * p[1] - beta * p[2] };
599 };
600 const auto advanced = [](const Vec& p, const Vec& d, double h) -> Vec {
601 return { p[0] + h * d[0], p[1] + h * d[1], p[2] + h * d[2] };
602 };
603
604 const Vec start { coefs[4], coefs[5], coefs[6] };
605 const Vec k1 = derivative(start);
606 const Vec k2 = derivative(advanced(start, k1, 0.5 * dt));
607 const Vec k3 = derivative(advanced(start, k2, 0.5 * dt));
608 const Vec k4 = derivative(advanced(start, k3, dt));
609
610 for (size_t i = 0; i < 3; ++i)
611 coefs[4 + i] = start[i] + dt / 6.0 * (k1[i] + 2.0 * k2[i] + 2.0 * k3[i] + k4[i]);
612
613 return coefs[4];
614}
uint32_t h
Definition InkPress.cpp:29

References h.