Add extended_rosenbrock_gradient1() and its tests.
[octave.git] / optimization / test_functions / extended_rosenbrock_gradient1.m
1 function g = extended_rosenbrock_gradient1(x)
2 ##
3 ## The gradient of the extended Rosenbrock function. See
4 ## extended_rosenbrock1.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 / 2;
18 g = zeros(n, 1);
19
20 % The extended Rosenbrock is simply a sum of Rosenbrock
21 % applications.
22 for k = [ 1 : m ]
23 y1 = x(2*k - 1);
24 y2 = x(2*k);
25
26 g_k = rosenbrock_gradient(y1, y2);
27
28 g(2*k - 1) = g(2*k - 1) + g_k(1);
29 g(2*k) = g(2*k) + g_k(2);
30 end
31 end