#include "header.h" int objfun(vec x,float *f,vec *df,mat *ddf,con spec)//spec shows what kind of value are we evaluating. { int i,j; float sum=0; float tmp; if(spec.f==1) // spec.f==1 means to evaluate the value of function { for(i=1;i=1&&i<=x.n-2))+cos(x.fp[i-1]*x.fp[i]+cos(x.fp[i-2]-x.fp[i-1]))*x.fp[i-1]*((float)(i>=2)); //since some of the item missing in some i, so i use the boolean function to decide if the item appers of not. df->fp[i]=tmp; } } if(spec.ddf==1) // spec.ddf==1 means to get the value of second derivative function which is a matrix { for(i=0;ii+2)tmp=0;//The derivative of f only contains x_{i-2} to x_{i+2}, hence the variales out of this range will lead the second derivative equal to 0. if(j==i-2) tmp=(x.fp[j+1]*sin(x.fp[j] - x.fp[j+1])*sin(x.fp[j+1]*x.fp[j+2] + cos(x.fp[j] - x.fp[j+1])))*(i>=2); if(j==i-1) tmp=(cos(x.fp[j] - x.fp[j+1])*cos(x.fp[j+1]*x.fp[j+2]+cos(x.fp[j]-x.fp[j+1]))+sin(x.fp[j] - x.fp[j+1])*(x.fp[j+2]+sin(x.fp[j] - x.fp[j+1]))*sin(x.fp[j+1]*x.fp[j+2] + cos(x.fp[j] - x.fp[j+1])))*(i>=1&&i<=x.n-2)+(cos(x.fp[j]*x.fp[j+1]+cos(x.fp[j-1]-x.fp[j]))-x.fp[j]*(x.fp[j+1] + sin(x.fp[j-1] - x.fp[j]))*sin(x.fp[j]*x.fp[j+1] + cos(x.fp[j-1] - x.fp[j])))*(i>=2); if(j==i) tmp=(-(cos(x.fp[j]-x.fp[j+1])*cos(x.fp[j+1]*x.fp[j+2]+cos(x.fp[j]-x.fp[j+1])))-pow(sin(x.fp[j]-x.fp[j+1]),2)*sin(x.fp[j+1]*x.fp[j+2]+cos(x.fp[j]-x.fp[j+1])))*(i<=x.n-3)+(-(cos(x.fp[j-1] - x.fp[j])*cos(x.fp[j]*x.fp[j+1] + cos(x.fp[j-1] - x.fp[j])))-pow(x.fp[j+1]+sin(x.fp[j-1] - x.fp[j]),2)*sin(x.fp[j]*x.fp[j+1] + cos(x.fp[j-1] - x.fp[j])))*(i>=1&&i<=x.n-2)+(-(pow(x.fp[j-1],2)*sin(x.fp[j-1]*x.fp[j] + cos(x.fp[j-2] - x.fp[j-1]))))*(i>=2); if(j==i+1) tmp=(cos(x.fp[j-1] - x.fp[j])*cos(x.fp[j]*x.fp[j+1] + cos(x.fp[j-1] - x.fp[j])) +sin(x.fp[j-1] - x.fp[j])*(x.fp[j+1] + sin(x.fp[j-2] - x.fp[j-1]))*sin(x.fp[j]*x.fp[j+1]+ cos(x.fp[j-1] - x.fp[j])))*(i<=x.n-3)+(cos(x.fp[j-1]*x.fp[j]+cos(x.fp[j-2] - x.fp[j-1]))-x.fp[j-1]*(x.fp[j] + sin(x.fp[j-2] - x.fp[j-1]))*sin(x.fp[j-1]*x.fp[j] + cos(x.fp[j-2] - x.fp[j-1])))*(i>=1&&i<=x.n-2); if(j==i+2) tmp=(x.fp[j-1]*sin(x.fp[j-2] - x.fp[j-1])*sin(x.fp[j-1]*x.fp[j] + cos(x.fp[j-2] - x.fp[j-1])))*(i<=x.n-3);// these second derivative are all made by the software mathematicas. ddf->fp[j*x.n+i]=tmp; } }} return 0; }