]> gitweb.michael.orlitzky.com - octave.git/blobdiff - optimization/test_functions/extended_powell_hessian1.m
Add extended_powell functions and their tests.
[octave.git] / optimization / test_functions / extended_powell_hessian1.m
diff --git a/optimization/test_functions/extended_powell_hessian1.m b/optimization/test_functions/extended_powell_hessian1.m
new file mode 100644 (file)
index 0000000..972e690
--- /dev/null
@@ -0,0 +1,38 @@
+function H = extended_powell_hessian1(x)
+  ##
+  ## The Hessian of the extended Powell function. See
+  ## extended_powell1.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 / 4;
+  H = zeros(n, n);
+
+  % The extended Powell is simply a sum of Powell
+  % applications.
+  for k = [ 1 : m ]
+    y1 = x(4*k - 3);
+    y2 = x(4*k - 2);
+    y3 = x(4*k - 1);
+    y4 = x(4*k);
+
+    H_k = powell_hessian(y1, y2, y3, y4);
+
+    for i = [ 1 : 4 ]
+      for j = [ 1 : 4 ]
+       H(4*(k-1) + i, 4*(k-1) + j) = ...
+         H(4*(k-1) + i, 4*(k-1) + j) + H_k(i,j);
+      end
+    end
+
+  end
+end