math_audio_test_functions/functions/schaffer_n2.rs
1//! Schaffer N2 test function
2
3use ndarray::Array1;
4
5/// Schaffer N.2 function - multimodal, 2D only
6/// Global minimum: f(x) = 0 at x = (0, 0)
7/// Bounds: x_i in [-100, 100]
8pub fn schaffer_n2(x: &Array1<f64>) -> f64 {
9 let x1 = x[0];
10 let x2 = x[1];
11 0.5 + ((x1.powi(2) + x2.powi(2)).sin().powi(2) - 0.5)
12 / (1.0 + 0.001 * (x1.powi(2) + x2.powi(2))).powi(2)
13}