Whats the deal with using floats and double in same mathematical expressions?
I have the foloowing function, and I just noticed that three parameters, eta phi and omega_2 are floats, the rest are doubles. Is this going to change anything, because at the moment my code doesnt do what I expect of it, but I cant see another issue, however I know that "curve_to_fit" is calculating incorrectly.
Code:
static double function2(int n, double y[])
double curve_to_fit[23],curve_to_fit_sum_abs = 0, c1[23], x_coeff_2[23], v1[23], v2[23];
float eta = y[0]; //parameters
float phi=y[1]; //parameters
float omega_2=y[2]; //parameters
int i;
for (i = 0; i<=22; i++)
{
v1[i] = (exp(a_global*2*pi)-cosh(a_global*b_global*init_T[i][0]));
v2[i] = sinh(a_global*b_global*init_T[i][0]);
x_coeff_2[i] = v1[i]/v2[i];
c1[i]= b_global*b_global*(x_coeff_2[i]*x_coeff_2[i]-1);
curve_to_fit[i] = c1[i]*exp(-2*a_global*init_T[i][1])+eta*((1+0.5*(4*a_global*a_global+1))*cos(init_T[i][1]+phi)-2*a_global*sin(init_T[i][1]+phi))+b_global*b_global-omega_2;
}
for (i = 0; i<=22; i++)
{
curve_to_fit_sum_abs = curve_to_fit_sum_abs + abs(curve_to_fit[i]);
printf("i=%d, c1[i] = %f, x_coeff_2[i] = %f, curve_to_fit[i] = %f\n",i, c1[i],x_coeff_2[i],curve_to_fit[i]); // printf("curve_to_fit = %f, curve_to_fit_sum_abs = %f\n",curve_to_fit[i], curve_to_fit_sum_abs);
}
return curve_to_fit_sum_abs;
}
Cheers