X-Git-Url: http://gitweb.michael.orlitzky.com/?p=octave.git;a=blobdiff_plain;f=optimization%2Ftest_functions%2Fextended_rosenbrock_gradient1.m;fp=optimization%2Ftest_functions%2Fextended_rosenbrock_gradient1.m;h=2fd3c8cc63b2c8033fb9ececcb2bb84f1b36bf5c;hp=0000000000000000000000000000000000000000;hb=b9f39a6f569f1c236246a859fe6d10203187e8ee;hpb=f81dbdae572c276be06e7cb9bbe2d6c5293e60ec diff --git a/optimization/test_functions/extended_rosenbrock_gradient1.m b/optimization/test_functions/extended_rosenbrock_gradient1.m new file mode 100644 index 0000000..2fd3c8c --- /dev/null +++ b/optimization/test_functions/extended_rosenbrock_gradient1.m @@ -0,0 +1,31 @@ +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