MCPcopy Create free account
hub / github.com/elftausend/graplot / as_plot

Method as_plot

src/polynomial.rs:39–64  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

37
38impl PlotArg for Polynomial {
39 fn as_plot(&self) -> crate::Plot {
40 let mut xs = [0.; 200];
41
42 let mut add = -100f64;
43 for x in &mut xs {
44 *x = add / 100.;
45 add += 1.;
46 }
47
48 let mut ys = [0.; 200];
49
50 let degree = self.coefficients.len() - 1;
51
52 for (i, y) in ys.iter_mut().enumerate() {
53 for (pow, coefficient) in self.coefficients.iter().enumerate() {
54 *y += coefficient * xs[i].powi((degree - pow) as i32);
55 }
56 }
57 Plot {
58 xs: vec![xs.to_vec()],
59 ys: vec![ys.to_vec()],
60 line_desc: vec![Default::default()],
61 axis_desc: Default::default(),
62 desc: Default::default(),
63 }
64 }
65}
66
67impl PlotArg for (Polynomial, Option<XEnd>) {

Callers 2

test_poly_1stFunction · 0.45
mainFunction · 0.45

Calls

no outgoing calls

Tested by 1

test_poly_1stFunction · 0.36