From 54c2041babd3d3b67c9d26162f44da66f66b12db Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Wed, 6 Mar 2013 20:16:01 -0500 Subject: [PATCH] Add powell_gradient(), powell_gradient1() and their tests. --- optimization/test_functions/powell_gradient.m | 12 ++++++++++++ optimization/test_functions/powell_gradient1.m | 12 ++++++++++++ tests/powell_gradient1_tests.m | 5 +++++ tests/powell_gradient_tests.m | 5 +++++ 4 files changed, 34 insertions(+) create mode 100644 optimization/test_functions/powell_gradient.m create mode 100644 optimization/test_functions/powell_gradient1.m create mode 100644 tests/powell_gradient1_tests.m create mode 100644 tests/powell_gradient_tests.m diff --git a/optimization/test_functions/powell_gradient.m b/optimization/test_functions/powell_gradient.m new file mode 100644 index 0000000..7cea917 --- /dev/null +++ b/optimization/test_functions/powell_gradient.m @@ -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 index 0000000..e21b315 --- /dev/null +++ b/optimization/test_functions/powell_gradient1.m @@ -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 index 0000000..dbc463d --- /dev/null +++ b/tests/powell_gradient1_tests.m @@ -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 index 0000000..84924aa --- /dev/null +++ b/tests/powell_gradient_tests.m @@ -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)); -- 2.43.2