Add extended_rosenbrock_hessian1() and its tests.
authorMichael Orlitzky <michael@orlitzky.com>
Fri, 8 Mar 2013 15:16:29 +0000 (10:16 -0500)
committerMichael Orlitzky <michael@orlitzky.com>
Fri, 8 Mar 2013 15:16:29 +0000 (10:16 -0500)
optimization/test_functions/extended_rosenbrock_hessian1.m [new file with mode: 0644]
tests/extended_rosenbrock_hessian1_tests.m [new file with mode: 0644]

diff --git a/optimization/test_functions/extended_rosenbrock_hessian1.m b/optimization/test_functions/extended_rosenbrock_hessian1.m
new file mode 100644 (file)
index 0000000..9c3415d
--- /dev/null
@@ -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 (file)
index 0000000..59eb6d7
--- /dev/null
@@ -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);