function g = extended_rosenbrock_gradient1(x) ## ## The gradient of the extended Rosenbrock function. See ## extended_rosenbrock1.m for more information. ## ## Since the number of arguments is variable, we take a vector ## instead of its individual components. ## n = length(x); if (odd(n)) ## 'm' below must be an integer. g = NA; return; end m = n / 2; g = zeros(n, 1); % The extended Rosenbrock is simply a sum of Rosenbrock % applications. for k = [ 1 : m ] y1 = x(2*k - 1); y2 = x(2*k); g_k = rosenbrock_gradient(y1, y2); g(2*k - 1) = g(2*k - 1) + g_k(1); g(2*k) = g(2*k) + g_k(2); end end