From c5435604f6ca4774b729d2b209bc32df4420aa69 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Wed, 6 Mar 2013 20:05:09 -0500 Subject: [PATCH] Add powell(), powell1() and their tests. --- optimization/test_functions/powell.m | 11 +++++++++++ optimization/test_functions/powell1.m | 11 +++++++++++ tests/powell1_tests.m | 16 ++++++++++++++++ tests/powell_tests.m | 5 +++++ 4 files changed, 43 insertions(+) create mode 100644 optimization/test_functions/powell.m create mode 100644 optimization/test_functions/powell1.m create mode 100644 tests/powell1_tests.m create mode 100644 tests/powell_tests.m diff --git a/optimization/test_functions/powell.m b/optimization/test_functions/powell.m new file mode 100644 index 0000000..5031316 --- /dev/null +++ b/optimization/test_functions/powell.m @@ -0,0 +1,11 @@ +function f = powell(x1,x2,x3,x4) + ## The Powell function. See Dennis & Schnabel, Appendix B, problem + ## #1. (The "regular" Powell function is simply the Extended Powell + ## with m=1). + ## + ## This function has a minimum at x=(0,0,0,0) with f(x) == 0. The + ## suggested starting point is x0=(3,-1,0,1). + ## + f = (x1 + 10*x2)^2 + 5*(x3 - x4)^2; + f = f + (x2 - 2*x3)^4 + 10*(x1 - x4)^4; +end diff --git a/optimization/test_functions/powell1.m b/optimization/test_functions/powell1.m new file mode 100644 index 0000000..b5e1771 --- /dev/null +++ b/optimization/test_functions/powell1.m @@ -0,0 +1,11 @@ +function f = powell1(x) + ## + ## A version of the Powell function which takes a column 4-vector as + ## an argument instead of four distinct arguments. + ## + if (length(x) == 4) + f = powell(x(1), x(2), x(3), x(4)); + else + f = NA; + end +end diff --git a/tests/powell1_tests.m b/tests/powell1_tests.m new file mode 100644 index 0000000..dbcf71e --- /dev/null +++ b/tests/powell1_tests.m @@ -0,0 +1,16 @@ +## Test the optimal point. + +unit_test_equals("powell1([0;0;0;0]) == 0", ... + 0, ... + powell1([0;0;0;0])); + +## It should fail with the wrong number of coordinates. +f = powell1([1;2;3]); +unit_test_equals("powell1 fails with too few coordinates", ... + true, ... + isna(f)); + +f = powell1([1;2;3;4;5]); +unit_test_equals("powell1 fails with too many coordinates", ... + true, ... + isna(f)); diff --git a/tests/powell_tests.m b/tests/powell_tests.m new file mode 100644 index 0000000..3e56c92 --- /dev/null +++ b/tests/powell_tests.m @@ -0,0 +1,5 @@ +## Test the optimal point. + +unit_test_equals("powell(0,0,0,0) == 0", ... + 0, ... + powell(0,0,0,0)); -- 2.43.2