https://github.com/severindenisenko/ode-solver
Solver for ordinary differential equations
https://github.com/severindenisenko/ode-solver
numerical-methods ode-solver
Last synced: 4 months ago
JSON representation
Solver for ordinary differential equations
- Host: GitHub
- URL: https://github.com/severindenisenko/ode-solver
- Owner: SeverinDenisenko
- Created: 2022-11-19T18:30:13.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-12-02T13:09:50.000Z (over 2 years ago)
- Last Synced: 2023-11-23T23:58:23.742Z (over 1 year ago)
- Topics: numerical-methods, ode-solver
- Language: C++
- Homepage:
- Size: 4.1 MB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ODE Solver
# Features
Can solve systems of ordinary differential equation by using methods:
* Runge-Kutta fourth order method
* Adams extrapolation n-th order
* Adams interpolation n-th order
* Rosenbrock method for autonomous systems
* Predictor-Corrector method using Adams extrapolation and interpolation methods# How to use
Create ODE using `std::function` and create context:
```c++
std::function(double t, std::vector x)> f =
[](double t, std::vector x) -> std::vector{
std::vector res(x.size());/*
* Your system. For example:
*/
res[0] = 10.0 * (x[1] - x[0]);
res[1] = x[0] * (28.0 - x[2]) - x[1];
res[2] = x[0] * x[1] - 8.0 * x[2] / 3.0;return res;
};Context context = Context(f)
```Then set the initial values, start and begin of integration and other parameters.
```c++
context.x_0 = {10, 10, 10};
context.t_begin = 0.0;
context.t_end = 100.0;
context.h = 5e-5; // Integration step
context.adams_order = 10; // Order of Adams methods
```Then you can create instance of `ODESolver`:
```c++
ODESolver odeSolver = ODESolver(context);
```Run integration by one of the methods: `odeSolver.rk()`, `odeSolver.ae()`, `odeSolver.ai()`. Then retrieve results from `odeSolver.Results`:
```c++
odeSolver.ae();std::ofstream ae("ae.dat");
for (auto &step: odeSolver.Result)
{
auto [ t, x ] = step;ae << std::fixed << std::setprecision(10) << t << " ";
for (auto &item: x)
{
ae << item << " ";
}ae << std::endl;
}ae.close();
````odeSolver.Result` has type of `std::vector>>`.
# How to compile and run test
Use Makefile by running:
```shell
make run
```Results will be stored in `ae.dat`, `ai.dat`, `rk.dat`, `precor.dat`, `rosen.dat`. Plot them using:
```shell
gnuplot plot.plt
```