mgh 0.1.12

A Collection of Moré-Garbow-Hilstrom https://dl.acm.org/doi/pdf/10.1145/355934.355936
Documentation
use std::f64::consts::E;

pub fn powell_badly_scaled(x: &[f64]) -> f64 {
    if x.len() != 2 {
        panic!("input dimension must be 2");
    }
    let x1 = x[0];
    let x2 = x[1];

    let f1 = 10000. * x1 * x2 - 1.;
    let f2 = E.powf(-x1) + E.powf(-x2) - 1.0001;
    f1.powi(2) + f2.powi(2)
}

pub fn init() -> Vec<f64> {
    vec![0., 1.]
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_powell_badly_scaled() {
        let x = init();
        let val = powell_badly_scaled(&x);
        assert!(val.is_finite());
    }
}