Skip to content

Repository files navigation

ba7lya.rk4

CI

4th order Runge-Kutta | 4阶龙格库塔算法

Header-only C++23 library, MIT licensed.

Usage

#include "rk4.hxx"

// dy/dx = -y, y(0) = 1  →  y(x) = e^(-x)
ba7lya::rk4::rk4 solver{[](double /*x*/, double y) noexcept { return -y; }};

double x = 0.0;
double y = 1.0;
solver(x, y, /*h = */0.1, /*steps = */20); // integrate to x = 2.0

solver.step(x, y, 0.1); // or take a single step

The ODE is stored directly (no std::function type erasure), so the integrator is reentrant, thread-safe on its own copies, and usable in constexpr contexts.

Building (vcpkg manifest mode)

The repo vendors vcpkg as a submodule at thirdparty/vcpkg:

git submodule update --init --recursive
cmake --preset MSVC-2022-x64-Ninja   # or GCC-linux-x64-Ninja on Linux
cmake --build --preset MSVC-2022-x64-Debug
ctest --preset MSVC-2022-x64-Test

Options: ba7lya.rk4_BUILD_DEMO (ON), ba7lya.rk4_BUILD_TEST (ON when top-level), ba7lya.rk4_BUILD_BENCHMARK (OFF).

Consuming as an installed dependency:

find_package(ba7lya.rk4 CONFIG REQUIRED)
target_link_libraries(main PRIVATE ba7lya::rk4)

References

Runge-Kutta methods @wikipedia

License

MIT — see LICENSE.

About

4th order Runge-Kutta | 4阶龙格库塔算法

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages