1use std::{error::Error,
2 fs::File,
3 io::Write};
4use curve_sampling::Sampling;
5
6
7type R = Result<(), Box<dyn Error>>;
8
9fn main() -> R {
10 let mut fh = File::create("/tmp/sin_inv_x.gp")?;
11 write!(fh, "set terminal pngcairo\n\
12 set grid\n")?;
13 let mut d = 0;
14 let mut save = |s: &Sampling, n, title| -> R {
15 d += 1;
16 let fname = format!("/tmp/sin_inv_x{}.dat", d);
17 s.write(&mut File::create(&fname)?)?;
18 write!(fh, "set output \"sin_inv_x{}.png\"\n\
19 plot '{}' with l lt 1 lw 2 title \"{} ({} pts)\"\n",
20 d, &fname, title, n)?;
21 write!(fh, "set output \"sin_inv_x{}_p.png\"\n\
22 plot '{}' with l lt 5 lw 2 title \"{}\", \
23 '{}' with p lt 3 pt 5 ps 0.2 title \"points ({})\"\n",
24 d, &fname, title, &fname, n)?;
25 Ok(())
26 };
27
28 let f = |x: f64| x * (1. / x).sin();
29 let s = Sampling::fun(f, -0.4, 0.4).n(227).build();
30 save(&s, 227, "x sin(1/x)")?;
31 let s = Sampling::fun(f, -0.4, 0.4).n(389).build();
32 save(&s, 389, "x sin(1/x)")?;
33
34 let s = Sampling::fun(|x: f64| (1. / x).sin(), -0.4, 0.4).n(391).build();
35 save(&s, 391, "sin(1/x)")?;
36
37 Ok(())
38}