]> gitweb.michael.orlitzky.com - octave.git/blob - optimization/test_functions/trigonometric_gradient1.m
134ce8699bebb2f850f427df344a56b6f086d14f
[octave.git] / optimization / test_functions / trigonometric_gradient1.m
1 function g = trigonometric_gradient1(x)
2 ##
3 ## The gradient of the trigonometric function. See trigonometric1.m
4 ## for more information.
5 ##
6 n = length(x);
7 g = zeros(n,1);
8
9 cos_sum = sum(cos(x));
10
11 for k = [ 1 : n ]
12 f_k = n - cos_sum + k*(1 - cos(x(k))) - sin(x(k));
13
14 for j = [ 1 : n ]
15 ## Add to the jth component of g the partial of f^2 with
16 ## respect to x(j). The first term that we add here exists
17 ## regardless of j.
18 g(j) = g(j) + 2*f_k*sin(x(j));
19
20 if (j == k)
21 ## But this term vanishes when j != k.
22 g(j) = g(j) + 2*f_k*k*sin(x(k)) - 2*f_k*cos(x(k));
23 end
24 end
25 end
26
27 end