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