From c692c7c3a2d7af4881a1d5820fb8cb712653740b Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Thu, 10 Mar 2022 14:13:57 -0500 Subject: [PATCH] make newtons_method more accurate --- src/function.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/function.rs b/src/function.rs index 3f5b248..1578604 100644 --- a/src/function.rs +++ b/src/function.rs @@ -306,7 +306,8 @@ impl FunctionEntry { self.min_x = min_x; self.max_x = max_x; - let resolution: f64 = (self.pixel_width as f64 / (self.max_x - self.min_x).abs()) as f64; + let threshold: f64 = + ((self.pixel_width as f64 / (self.max_x - self.min_x).abs()) as f64) / 2.0; let (back_values, integral, derivative) = self.run_back(); self.output.back = Some(back_values); @@ -317,7 +318,7 @@ impl FunctionEntry { if do_extrema { self.output.extrema = Some( newtons_method( - resolution, + threshold, self.min_x..self.max_x, self.output.derivative.to_owned().unwrap(), &|x: f64| self.function.get_derivative_1(x), @@ -333,7 +334,7 @@ impl FunctionEntry { if do_roots { self.output.roots = Some( newtons_method( - resolution, + threshold, self.min_x..self.max_x, self.output.back.to_owned().unwrap(), &|x: f64| self.function.get(x),