]> gitweb.michael.orlitzky.com - octave.git/commitdiff
Add powell_gradient(), powell_gradient1() and their tests.
authorMichael Orlitzky <michael@orlitzky.com>
Thu, 7 Mar 2013 01:16:01 +0000 (20:16 -0500)
committerMichael Orlitzky <michael@orlitzky.com>
Thu, 7 Mar 2013 01:16:01 +0000 (20:16 -0500)
optimization/test_functions/powell_gradient.m [new file with mode: 0644]
optimization/test_functions/powell_gradient1.m [new file with mode: 0644]
tests/powell_gradient1_tests.m [new file with mode: 0644]
tests/powell_gradient_tests.m [new file with mode: 0644]

diff --git a/optimization/test_functions/powell_gradient.m b/optimization/test_functions/powell_gradient.m
new file mode 100644 (file)
index 0000000..7cea917
--- /dev/null
@@ -0,0 +1,12 @@
+function g = powell_gradient(x1,x2,x3,x4)
+  ##
+  ## The gradient of the Powell function. See powell.m for more
+  ## information.
+  ##
+  f_x1 = 40*(x1 - x4)^3 + 2*x1 + 20*x2;
+  f_x2 = 4*(x2 - 2*x3)^3 + 20*x1 + 200*x2;
+  f_x3 = -8*(x2 - 2*x3)^3 + 10*x3 - 10*x4;
+  f_x4 = -40*(x1 - x4)^3 - 10*x3 + 10*x4;
+
+  g = [f_x1; f_x2; f_x3; f_x4];
+end
diff --git a/optimization/test_functions/powell_gradient1.m b/optimization/test_functions/powell_gradient1.m
new file mode 100644 (file)
index 0000000..e21b315
--- /dev/null
@@ -0,0 +1,12 @@
+function g = powell_gradient1(x)
+  ##
+  ## A version of the powell_gradient() function which takes a column
+  ## 4-vector instead of four distinct arguments. See
+  ## powell_gradient.m for more information.
+  ##
+  if (length(x) == 4)
+    g = powell_gradient(x(1), x(2), x(3), x(4));
+  else
+    g = NA;
+  end
+end
diff --git a/tests/powell_gradient1_tests.m b/tests/powell_gradient1_tests.m
new file mode 100644 (file)
index 0000000..dbc463d
--- /dev/null
@@ -0,0 +1,5 @@
+## The gradient should be zero at the optimal point.
+
+unit_test_equals("powell_gradient1([0;0;0;0]) == 0", ...
+                0, ...
+                powell_gradient1([0;0;0;0]));
diff --git a/tests/powell_gradient_tests.m b/tests/powell_gradient_tests.m
new file mode 100644 (file)
index 0000000..84924aa
--- /dev/null
@@ -0,0 +1,5 @@
+## The gradient should be zero at the optimal point.
+
+unit_test_equals("powell_gradient(0,0,0,0) == 0", ...
+                0, ...
+                powell_gradient(0,0,0,0));