]> gitweb.michael.orlitzky.com - octave.git/blobdiff - optimization/test_functions/trigonometric_hessian1.m
Add trigonometric functions and their tests.
[octave.git] / optimization / test_functions / trigonometric_hessian1.m
diff --git a/optimization/test_functions/trigonometric_hessian1.m b/optimization/test_functions/trigonometric_hessian1.m
new file mode 100644 (file)
index 0000000..f3e40a4
--- /dev/null
@@ -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