refactor newtons_method

This commit is contained in:
Simon Gardling 2022-03-24 00:07:59 -04:00
parent 8240c041c6
commit 7dc7167a57

View File

@ -186,12 +186,11 @@ pub fn newtons_method(
) -> Vec<f64> {
data.iter()
.tuple_windows()
.filter(|(prev, curr)| !(prev.y.is_nan() | curr.y.is_nan()))
.map(|(prev, curr)| {
if prev.y.signum() != curr.y.signum() {
// actual start of newton's method
let x = {
let mut x1: f64 = prev.x;
.filter(|(prev, curr)| !prev.y.is_nan() && !curr.y.is_nan())
.filter(|(prev, curr)| prev.y.signum() != curr.y.signum())
.map(|(prev, _)| prev.x)
.map(|start_x| {
let mut x1: f64 = start_x;
let mut x2: f64;
let mut fail: bool = false;
loop {
@ -214,11 +213,6 @@ pub fn newtons_method(
true => f64::NAN,
false => x1,
}
};
return x;
}
f64::NAN
})
.filter(|x| !x.is_nan())
.collect()