Hi guys,

so after some studying, I think that for my problem I actually want surface1.c as the basis to manipulate for my algorithm, not sure though, just think that.

I have adjusted the program so that it now compiles and runs with my function however I dont think I have quite understood my way around all the function pointers and the struct thats in there too.

The data I have that I am trying to fit is:

Code:

double tx[5] = {1, 2, 3, 4, 5};
double tz[5] = {1.2, 2.693, 4.325, 6.131, 8.125};

On a graph tx would be on the x axis, and tz on the y. Im not sure what the 'tx' array in the example is.

So I am trying to fit the above data to the algorithm:

Code:

double f(double tz, const double *p){
double Fitted_Curve[5] = {0};
int i;
double invtrig = 0, x = 0;
for (i = 0; i <sizeof(tz)-1; i++)
{
invtrig = arcsinh(sinh(p[2])*exp(p[0]*(i+1)*2*3.145));
Fitted_Curve[i] = (1/(p[0]*p[1]))*(p[2]-invtrig);
x += pow((tz[i]-Fitted_Curve[i]), 2);
}
return x;
}

However it wont compile with the above, because I am asking for tz[i]. The following algorithm it will compile and run with, however it produces incorrect results, as its not "fitting" the correct curve (I dont think)

Code:

double f(double tz, const double *p){
double Fitted_Curve = 0;//[5] = {0};
int i;
double invtrig = 0, x = 0;
// for (i = 0; i <sizeof(tz)-1; i++)
// {
invtrig = arcsinh(sinh(p[2])*exp(p[0]*(i+1)*2*3.145));
Fitted_Curve = (1/(p[0]*p[1]))*(p[2]-invtrig);
x = pow((tz-Fitted_Curve), 2);
// }
return x;
}

I dont really need tx because its just 1,2,3,4,5 which I planned on using i+1 for.

Please can someone have a look and see if they can simplify the algorithm, or at least help me to simplify it so that I can "fit this equation"?

Thanks