-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimulate.cpp
More file actions
36 lines (30 loc) · 853 Bytes
/
simulate.cpp
File metadata and controls
36 lines (30 loc) · 853 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*********************************************
*
* simulate.cpp
*
* Robert A McDougal
* 5 June 2020
*
********************************************/
/*
compile on linux or mac via:
gcc -shared -o simulate.so -Wall -fPIC simulate.cpp
*/
#include <cstdint>
extern "C" {
void simulate(int64_t n, double* xs, double* ys, double* zs, double x, double y, double z);
}
const double sigma = 10;
const double beta = 8. / 3.;
const double rho = 28;
const double dt = 0.01;
void simulate(int64_t n, double* xs, double* ys, double* zs, double x, double y, double z) {
for (int64_t i = 0; i < n; i++) {
double dxdt = sigma * (y - x);
double dydt = x * (rho - z) - y;
double dzdt = x * y - beta * z;
xs[i] = x = x + dxdt * dt;
ys[i] = y = y + dydt * dt;
zs[i] = z = z + dzdt * dt;
}
}