Hi,
This maybe do something with you use number in an integer form, then it converts the results from double to integer, which may cause the lose of precision.
I have changed all the integer constants to a float type. e.g from 2 to 2.0.
The code is listed as following:
if( Kt == 0.0 || Kd == 0.0)
{
A = NANUM;
return;
}
double a=2.0/(3.0*Kt);
double b=1.0/(3.0*Kd*Kt);
double c=-(C)/(3.0*Kd*Kt);
double Q=((a^2.0)-3.0*b)/9.0;
double R=(2.0*(a^3.0)-9.0*a*b+27.0*c)/54.0;
double D=Q^3.0-R^2.0;
if (R == 0.0)
{
A = NANUM;
return;
}
double F;
if (R>=0)
{
F=1.0;
}
else
{
F=-1.0;
}
double t;
double W;
double Cm;
if (D>=0.0)
{
t=atan((sqrt(D))/R);
Cm=-2.0*sqrt(Q)*cos((t+2.0*PI)/3.0)-(a/3.0);
}
else
{
W=(sqrt(-D)+abs(R))^(1.0/3.0);
Cm=-F*(W+(Q/W))-(a/3.0);
}
A=Cm*Em+2.0*Kd*(Cm^2.0)*Ed+3.0*Kd*Kt*(Cm^3.0)*Et;
Now using the code, I can get the fitted curve close to the data.
But the fitted parameters seem not very good comparing with the initialized parameters which are good enough as you mentioned.
Is there something else wrong? I cannot be sure.
Zachary
OriginLab GZ Office
Edited by - zachary_origin on 08/28/2006 09:01:40 AM