rename BackingFunction::derivative to BackingFunction::get_derivative_1

This commit is contained in:
Simon Gardling 2022-03-10 08:49:17 -05:00
parent 7e77f8b40d
commit cda3853a01
2 changed files with 8 additions and 5 deletions

View File

@ -138,7 +138,7 @@ impl FunctionEntry {
if let Some(i) = x_data.get_index(x) { if let Some(i) = x_data.get_index(x) {
derivative_cache[i] derivative_cache[i]
} else { } else {
Value::new(x, self.function.derivative(x)) Value::new(x, self.function.get_derivative_1(x))
} }
}) })
.collect(); .collect();
@ -175,7 +175,7 @@ impl FunctionEntry {
self.output.derivative = Some( self.output.derivative = Some(
(0..self.pixel_width) (0..self.pixel_width)
.map(|x| (x as f64 / resolution as f64) + self.min_x) .map(|x| (x as f64 / resolution as f64) + self.min_x)
.map(|x| Value::new(x, self.function.derivative(x))) .map(|x| Value::new(x, self.function.get_derivative_1(x)))
.collect(), .collect(),
); );
} }
@ -311,7 +311,7 @@ impl FunctionEntry {
let mut x2: f64; let mut x2: f64;
let mut fail: bool = false; let mut fail: bool = false;
loop { loop {
x2 = x1 - (self.function.get(x1) / self.function.derivative(x1)); x2 = x1 - (self.function.get(x1) / self.function.get_derivative_1(x1));
if !(self.min_x..self.max_x).contains(&x2) { if !(self.min_x..self.max_x).contains(&x2) {
fail = true; fail = true;
break; break;
@ -365,7 +365,8 @@ impl FunctionEntry {
let mut fail: bool = false; let mut fail: bool = false;
loop { loop {
x2 = x1 x2 = x1
- (self.function.derivative(x1) / self.function.get_derivative_2(x1)); - (self.function.get_derivative_1(x1)
/ self.function.get_derivative_2(x1));
if !(self.min_x..self.max_x).contains(&x2) { if !(self.min_x..self.max_x).contains(&x2) {
fail = true; fail = true;
break; break;

View File

@ -34,7 +34,9 @@ impl BackingFunction {
pub fn get(&self, x: f64) -> f64 { self.function.eval(&[x]).unwrap_or(f64::NAN) } pub fn get(&self, x: f64) -> f64 { self.function.eval(&[x]).unwrap_or(f64::NAN) }
pub fn derivative(&self, x: f64) -> f64 { self.derivative_1.eval(&[x]).unwrap_or(f64::NAN) } pub fn get_derivative_1(&self, x: f64) -> f64 {
self.derivative_1.eval(&[x]).unwrap_or(f64::NAN)
}
pub fn get_derivative_2(&self, x: f64) -> f64 { pub fn get_derivative_2(&self, x: f64) -> f64 {
self.derivative_2.eval(&[x]).unwrap_or(f64::NAN) self.derivative_2.eval(&[x]).unwrap_or(f64::NAN)