refactor newtons_method
This commit is contained in:
parent
8240c041c6
commit
7dc7167a57
16
src/misc.rs
16
src/misc.rs
@ -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()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user