--- /dev/null
+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
--- /dev/null
+## Test the optimal point.
+
+for m = [ 1 : 10 ]
+ x = repmat([1;1], m, 1);
+
+ msg = sprintf("extended_rosenbrock1([1;1;...]) == 0 (m = %d)", m);
+ unit_test_equals(msg, 0, extended_rosenbrock1(x));
+end
+
+## It should fail with the wrong number of coordinates.
+f = extended_rosenbrock1([1]);
+unit_test_equals("extended_rosenbrock1 fails when length(x) is odd", ...
+ true, ...
+ isna(f));