--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+## 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]));
--- /dev/null
+## 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));