1 function g = trigonometric_gradient1(x)
3 % The gradient of the trigonometric function. See trigonometric1.m
4 % for more information.
12 f_k = n - cos_sum + k*(1 - cos(x(k))) - sin(x(k));
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
18 g(j) = g(j) + 2*f_k*sin(x(j));
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));