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