--- /dev/null
+function f = trigonometric1(x)
+ ##
+ ## The trigonometric function. See More, Garbow, and Hillstrom,
+ ## function #26.
+ ##
+ ## This function has a minimum with f(x) == 0. The suggested
+ ## starting point is x0=(1/n, 1/n,...).
+ ##
+ n = length(x);
+ f = 0;
+
+ cos_sum = sum(cos(x));
+
+ for k = [ 1 : n ]
+ f_k = n - cos_sum + k*(1 - cos(x(k))) - sin(x(k));
+ f = f + (f_k)^2;
+ end
+end
--- /dev/null
+function g = trigonometric_gradient1(x)
+ ##
+ ## The gradient of the trigonometric function. See trigonometric1.m
+ ## for more information.
+ ##
+ n = length(x);
+ g = zeros(n,1);
+
+ cos_sum = sum(cos(x));
+
+ for k = [ 1 : n ]
+ f_k = n - cos_sum + k*(1 - cos(x(k))) - sin(x(k));
+
+ for j = [ 1 : n ]
+ ## Add to the jth component of g the partial of f^2 with
+ ## respect to x(j). The first term that we add here exists
+ ## regardless of j.
+ g(j) = g(j) + 2*f_k*sin(x(j));
+
+ if (j == k)
+ ## But this term vanishes when j != k.
+ g(j) = g(j) + 2*f_k*k*sin(x(k)) - 2*f_k*cos(x(k));
+ end
+ end
+ end
+
+end
--- /dev/null
+function H = trigonometric_hessian1(x)
+ ##
+ ## The Hessian of the Trigonometric function. See trigonometric1.m
+ ## for more information. Not my implementation. Too ugly to
+ ## recreate.
+ ##
+ n = length(x);
+ H = zeros(n,n);
+
+ cos_sum = sum(cos(x));
+
+ for i = 1 : n
+ H(i,i) = sin ( x(i) );
+ end
+
+ s = 0;
+ for j = 1 : n
+ th = cos ( x(j) );
+ t = ( n + j ) - H(j,j) - cos_sum - j * th;
+ s = s + t;
+ for k = 1 : j-1
+ H(j,k) = 2 * ( sin ( x(k) ) * ( ( n + j + k ) * H(j,j) - th ) ...
+ - H(j,j) * cos ( x(k) ) );
+ end
+ H(j,j) = ( j * ( j + 2 ) + n ) * H(j,j)^2 + th * ...
+ ( th - ( 2 * j + 2 ) * H(j,j) ) + t * ( j * th + H(j,j) );
+ end
+
+ for j = 1 : n
+ H(j,j) = 2 * ( H(j,j) + cos ( x(j) ) * s );
+ end
+
+ for i = 1 : n
+ H(i,i+1:n) = H(i+1:n,i);
+ end
+
+end
--- /dev/null
+## Test the optimal point.
+
+x = [0.24307;
+ 0.61268];
+
+unit_test_equals("trigonometric1([0.24307; 0.61268]) == 0", ...
+ true, ...
+ norm(trigonometric1(x)) < 1e-6);
--- /dev/null
+## Test the optimal point.
+
+x = [0.24307;
+ 0.61268];
+
+unit_test_equals("trigonometric_gradient1([0.24307; 0.61268]) == 0", ...
+ true, ...
+ norm(trigonometric_gradient1(x)) < 1e-5);