Add extended_powell functions and their tests.
[octave.git] / optimization / test_functions / extended_powell_gradient1.m
1 function g = extended_powell_gradient1(x)
2 ##
3 ## The gradient of the extended Powell function. See
4 ## extended_powell1.m for more information.
5 ##
6 ## Since the number of arguments is variable, we take a vector
7 ## instead of its individual components.
8 ##
9 n = length(x);
10
11 if (odd(n))
12 ## 'm' below must be an integer.
13 g = NA;
14 return;
15 end
16
17 m = n / 4;
18 g = zeros(n, 1);
19
20 % The extended Powell is simply a sum of Powell
21 % applications.
22 for k = [ 1 : m ]
23 y1 = x(4*k - 3);
24 y2 = x(4*k - 2);
25 y3 = x(4*k - 1);
26 y4 = x(4*k);
27
28 g_k = powell_gradient(y1, y2, y3, y4);
29
30 for i = [ 1 : 4 ]
31 g(4*(k-1) + i) = g(4*(k-1) + i) + g_k(i);
32 end
33
34 end
35 end