pub fn newton<S, T>(dist: &T, y: S, mu: S, epsilon: S) -> S 
where
    S: Float,
    T: Univariate<S, S>
{
    let fx0 = dist.cdf(mu);
    if fx0 + epsilon >= y && fx0 - epsilon <= y {
        return mu;
    }
    let mut x = if fx0 > mu {
        mu + S::epsilon()
    } else {
        mu - S::epsilon()
    };
    loop {
        let fx = dist.cdf(x);
        if fx + epsilon >= y && fx - epsilon <= y {
            break;
        }
        let df = if x >= mu {
            deriv_with_fx(dist, x, fx, epsilon)
        } else {
            deriv_with_fx(dist, x, fx, -epsilon)
        };
        x = x + (y - fx) / df;
    }
    x
}
/// Newton method to solve equations.
Newton method to solve equations.
Newton method to solve equations .
pub fn newton<S, T>(dist: &T, y: S, mu: S, epsilon: S) -> S 
where
    S: Float,
    T: Univariate<S, S>
{
    let fx0 = dist.cdf(mu);
    if fx0 + epsilon >= y && fx0 - epsilon <= y {
        return mu;
    }
    let mut x = if fx0 > mu {
        mu + S::epsilon()
    } else {
        mu - S::epsilon()
    };
    loop {
        let fx = dist.cdf(x);
        if fx + epsilon >= y && fx - epsilon <= y {
            break;
        }
        let df = if x >= mu {
            deriv_with_fx(dist, x, fx, epsilon)
        } else {
            deriv_with_fx(dist, x, fx, -epsilon)
        };
        x = x + (y - fx) / df;
    }
    x
}
pub fn newton < S , T > ( dist : & T , y : S , mu : S , epsilon : S ) -> S where S : Float , T : Univariate < S , S > { let fx0 = dist . cdf ( mu ) ; if fx0 + epsilon >= y && fx0 - epsilon <= y { return mu ; } let mut x = if fx0 > mu { mu + S :: epsilon ( ) } else { mu - S :: epsilon ( ) } ; loop { let fx = dist . cdf ( x ) ; if fx + epsilon >= y && fx - epsilon <= y { break ; } let df = if x >= mu { deriv_with_fx ( dist , x , fx , epsilon ) } else { deriv_with_fx ( dist , x , fx , - epsilon ) } ; x = x + ( y - fx ) / df ; } x }
Newton method to solve equations.
Newton method to solve equations .
dist
&T
y
S
mu
S
epsilon
S
dist
&T
y
S
mu
S
epsilon
S