Yeah i had inititalised it.

the problem is the function i have shown you is sent by main to another function to do a downhill simplex method on.

The function i have been showing you is in full

Code:

double rosen(double x[])
{
double c[5];
double Fitted_Curve[5];
double Error_Vector[5];
int i;
double Actual_Output[5]={1.2, 2.693, 4.325, 6.131, 8.125};
double Input[5]={1, 2, 3, 4, 5};
double sum = 0;
for (i = 0; i <= 4; i++)
{
c[i] = -1/atanh((exp(x[0]*2*pi)-cosh(x[0]*x[1]*Actual_Output[i]))/sinh(x[0]*x[1]*Actual_Output[i]));
Fitted_Curve[i] = (1/(x[0]*x[1]))*(c[i]-asinh(sinh(c[i])*exp(x[0]*Input[i]*2*pi)));
Error_Vector[i] = Actual_Output[i]-Fitted_Curve[i];
}
for (i = 0; i <= 4; i++)
{
sum = sum + Error_Vector[i]*Error_Vector[i];
}
return sum;
}

it is sent to the function simplex in main such that:

Code:

int main()
{
double start[] = {1,1.0,1};
double min;
int i;
min=simplex(rosen,start,3,1.0e-4,1,my_constraints);
//min=simplex(rosen,start,2,1.0e-4,1,NULL);
for (i=0;i<3;i++) {
printf("%f\n",start[i]);
}
return 0;
}

my_constraints is just another function sent to simplex

and when i say nan, i mean 1.#QNAN0