#include "header.h" //This function evaluates the equation N-2 SIGMA i=1 {sin(xi * xi+1 + cos(xi-1 - xi))} CountSpecs Function(Vector Vect, InputSpecs ISpecs, CountSpecs CSpecs) { static int fCounter=0, DfCounter=0, DDfCounter=0; int i; if( CSpecs.f==1||CSpecs.Df==1||CSpecs.DDf==1) { CountSpecs CSpecs; CSpecs.f=fCounter; CSpecs.Df=DfCounter; CSpecs.DDf=DDfCounter; return CSpecs; //if any of these Specs are 0, then the function is not evaluated and the counts are returned } if(ISpecs.f==1) { //evaluates the function sin(x(i)*x(i+1)+cos(x(i-1)-x(i))) printf("f:\n %f\n",sin((Vect.fp[i])*(Vect.fp[(i+1)])+cos((Vect.fp[(i-1)])-(Vect.fp[i])))); fCounter++; } if(ISpecs.Df==1) { //evalues the gradient of the function //can be made more efficient by precomputing some of these repeated values printf("Df:\n%f\t%f\t%f\t%f\n",-(cos(Vect.fp[1]*Vect.fp[2] + cos(Vect.fp[0] - Vect.fp[1]))*sin(Vect.fp[0] - Vect.fp[1])), cos(Vect.fp[1]*Vect.fp[2] + cos(Vect.fp[0] - Vect.fp[1]))*(Vect.fp[2] + sin(Vect.fp[0] - Vect.fp[1])), Vect.fp[1]*cos(Vect.fp[1]*Vect.fp[2] + cos(Vect.fp[0] - Vect.fp[1])),0.0); DfCounter++; } if(ISpecs.DDf==1) { //evalues the hessian of the function //can be made more efficient by precomputing some of these repeated values printf("DDf:\n%f\t%f\t%f\t%f\n",-(cos(Vect.fp[0] - Vect.fp[1])*cos(Vect.fp[1]*Vect.fp[2] + cos(Vect.fp[0] - Vect.fp[1]))) - pow(sin(Vect.fp[0] - Vect.fp[1]),2)*sin(Vect.fp[1]*Vect.fp[2] + cos(Vect.fp[0] - Vect.fp[1])),cos(Vect.fp[0] - Vect.fp[1])*cos(Vect.fp[1]*Vect.fp[2] + cos(Vect.fp[0] - Vect.fp[1])) + sin(Vect.fp[0] - Vect.fp[1])*(Vect.fp[2] + sin(Vect.fp[0] - Vect.fp[1]))*sin(Vect.fp[1]*Vect.fp[2] + cos(Vect.fp[0] - Vect.fp[1])),Vect.fp[1]*sin(Vect.fp[0] - Vect.fp[1])*sin(Vect.fp[1]*Vect.fp[2] + cos(Vect.fp[0] - Vect.fp[1])),0.0); printf("%f\t%f\t%f\t%f\n",cos(Vect.fp[0] - Vect.fp[1])*cos(Vect.fp[1]*Vect.fp[2] + cos(Vect.fp[0] - Vect.fp[1])) + sin(Vect.fp[0] - Vect.fp[1])*(Vect.fp[2] + sin(Vect.fp[0] - Vect.fp[1]))*sin(Vect.fp[1]*Vect.fp[2] + cos(Vect.fp[0] - Vect.fp[1])),-(cos(Vect.fp[0] - Vect.fp[1])*cos(Vect.fp[1]*Vect.fp[2] + cos(Vect.fp[0] - Vect.fp[1]))) - pow(Vect.fp[2] + sin(Vect.fp[0] - Vect.fp[1]),2)*sin(Vect.fp[1]*Vect.fp[2] + cos(Vect.fp[0] - Vect.fp[1])),cos(Vect.fp[1]*Vect.fp[2] + cos(Vect.fp[0] - Vect.fp[1])) - Vect.fp[1]*(Vect.fp[2] + sin(Vect.fp[0] - Vect.fp[1]))*sin(Vect.fp[1]*Vect.fp[2] + cos(Vect.fp[0] - Vect.fp[1])),0.0); printf("%f\t%f\t%f\t%f\n",Vect.fp[1]*sin(Vect.fp[0] - Vect.fp[1])*sin(Vect.fp[1]*Vect.fp[2] + cos(Vect.fp[0] - Vect.fp[1])),cos(Vect.fp[1]*Vect.fp[2] + cos(Vect.fp[0] - Vect.fp[1])) - Vect.fp[1]*(Vect.fp[2] + sin(Vect.fp[0] - Vect.fp[1]))*sin(Vect.fp[1]*Vect.fp[2] + cos(Vect.fp[0] - Vect.fp[1])),-(pow(Vect.fp[1],2)*sin(Vect.fp[1]*Vect.fp[2] + cos(Vect.fp[0] - Vect.fp[1]))),0.0); printf("%f\t%f\t%f\t%f\n",0.0,0.0,0.0,0.0); DDfCounter++; } CSpecs.f=-1; CSpecs.Df=-1; //return nonsense counts CSpecs.DDf=-1; return CSpecs; }