1use std::{error::Error, process};
9
10const SIGMA: f64 = 10.0;
11const RHO: f64 = 28.0;
12const BETA: f64 = 8.0 / 3.0;
13
14pub fn generate_lorenz_points() -> Vec<(f64, f64)> {
15 let dt = 0.01;
16 let num_steps = 10000;
17
18 let mut x = 5.0;
19 let mut y = 18.0;
20 let mut z = 10.0;
21 let mut points = Vec::with_capacity(num_steps);
22
23 for _ in 0..num_steps {
24 let (dx, dy, dz) = lorenz(x, y, z, SIGMA, RHO, BETA).unwrap_or_else(|err| {
25 eprintln!("{:?}", err);
26 process::exit(1);
27 });
28 x += dx * dt;
29 y += dy * dt;
30 z += dz * dt;
31 points.push((x, y));
32 }
33 points
34}
35
36pub fn lorenz(
37 x: f64,
38 y: f64,
39 z: f64,
40 sigma: f64,
41 rho: f64,
42 beta: f64,
43) -> Result<(f64, f64, f64), Box<dyn Error>> {
44 let dx = sigma * (y - x);
45 let dy = x * (rho - z) - y;
46 let dz = x * y - beta * z;
47
48 Ok((dx, dy, dz))
49}