From 2b94bdc2496c384cd7cdb9d11aa7815e63c61f4a Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Fri, 8 Mar 2013 10:16:29 -0500 Subject: [PATCH] Add extended_rosenbrock_hessian1() and its tests. --- .../extended_rosenbrock_hessian1.m | 33 +++++++++++++++++++ tests/extended_rosenbrock_hessian1_tests.m | 9 +++++ 2 files changed, 42 insertions(+) create mode 100644 optimization/test_functions/extended_rosenbrock_hessian1.m create mode 100644 tests/extended_rosenbrock_hessian1_tests.m diff --git a/optimization/test_functions/extended_rosenbrock_hessian1.m b/optimization/test_functions/extended_rosenbrock_hessian1.m new file mode 100644 index 0000000..9c3415d --- /dev/null +++ b/optimization/test_functions/extended_rosenbrock_hessian1.m @@ -0,0 +1,33 @@ +function H = extended_rosenbrock_hessian1(x) + ## + ## The Hessian 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. + H = NA; + return; + end + + m = n / 2; + H = zeros(n, n); + + % The extended Rosenbrock is simply a sum of Rosenbrock + % applications. + for k = [ 1 : m ] + y1 = x(2*k - 1); + y2 = x(2*k); + + H_k = rosenbrock_hessian(y1, y2); + + H(2*k - 1, 2*k - 1) = H(2*k - 1, 2*k - 1) + H_k(1,1); + H(2*k - 1, 2*k) = H(2*k - 1, 2*k) + H_k(1,2); + H(2*k, 2*k - 1) = H(2*k, 2*k - 1) + H_k(2,1); + H(2*k, 2*k) = H(2*k, 2*k) + H_k(2,2); + end +end diff --git a/tests/extended_rosenbrock_hessian1_tests.m b/tests/extended_rosenbrock_hessian1_tests.m new file mode 100644 index 0000000..59eb6d7 --- /dev/null +++ b/tests/extended_rosenbrock_hessian1_tests.m @@ -0,0 +1,9 @@ +## When m=1 we should agree with rosenbrock_hessian1(). + +x = [4;5]; +f1 = rosenbrock_hessian1(x); +f2 = extended_rosenbrock_hessian1(x); + +unit_test_equals("(extended_)rosenbrock_hessian1 agree for m=1", ... + true, ... + f1 == f2); -- 2.43.2