]> gitweb.michael.orlitzky.com - octave.git/blobdiff - optimization/test_functions/extended_rosenbrock1.m
Add extended_rosenbrock1() and its tests.
[octave.git] / optimization / test_functions / extended_rosenbrock1.m
diff --git a/optimization/test_functions/extended_rosenbrock1.m b/optimization/test_functions/extended_rosenbrock1.m
new file mode 100644 (file)
index 0000000..1f54520
--- /dev/null
@@ -0,0 +1,30 @@
+function f = extended_rosenbrock1(x)
+  ##
+  ## The extended Rosenbrock function. See Dennis & Schnabel, Appendix
+  ## B, problem #1.
+  ##
+  ## This function has a minimum at x=(1,1,...,1) with f(x) == 0. The
+  ## suggested starting point is x0=(-1.2, 1,-1.2, 1,...,-1.2, 1).
+  ## 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.
+    f = NA;
+    return;
+  end
+
+  m = n / 2;
+  f = 0;
+
+  % The extended Rosenbrock is simply a sum of Rosenbrock
+  % applications.
+  for k = [ 1 : m ]
+    y1 = x(2*k - 1);
+    y2 = x(2*k);
+    f_k = rosenbrock(y1, y2);
+    f = f + f_k;
+  end
+end