math_audio_test_functions/functions/powell.rs
1//! Powell test function
2
3use ndarray::Array1;
4
5/// Powell function - unimodal but ill-conditioned
6/// Global minimum: f(x) = 0 at x = (0, 0, ..., 0)
7/// Bounds: x_i in [-4, 5]
8pub fn powell(x: &Array1<f64>) -> f64 {
9 let n = x.len();
10 let mut sum = 0.0;
11 for i in (0..n).step_by(4) {
12 if i + 3 < n {
13 let x1 = x[i];
14 let x2 = x[i + 1];
15 let x3 = x[i + 2];
16 let x4 = x[i + 3];
17 sum += (x1 + 10.0 * x2).powi(2)
18 + 5.0 * (x3 - x4).powi(2)
19 + (x2 - 2.0 * x3).powi(4)
20 + 10.0 * (x1 - x4).powi(4);
21 }
22 }
23 sum
24}