X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=optimization%2Ftest_functions%2Ftrigonometric_gradient1.m;fp=optimization%2Ftest_functions%2Ftrigonometric_gradient1.m;h=134ce8699bebb2f850f427df344a56b6f086d14f;hb=da77431bfbbb5fed8835d09aeea0de7eb7f6194a;hp=0000000000000000000000000000000000000000;hpb=e5d2c4a2963be5eb6c767b47d3c7427db3d00ec4;p=octave.git diff --git a/optimization/test_functions/trigonometric_gradient1.m b/optimization/test_functions/trigonometric_gradient1.m new file mode 100644 index 0000000..134ce86 --- /dev/null +++ b/optimization/test_functions/trigonometric_gradient1.m @@ -0,0 +1,27 @@ +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