The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum
 Origin Forum
 NLSF vs. Solver in Excel
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Bill Choi

Hong Kong
Posts

Posted - 10/16/2006 :  07:09:05 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi all,

I've encounter problem again. When I try to perform fitting with my scripts(which can be complied) and the 'solver' plugin in excel, they give different responses. For examples, when K1=150000 and K2=120000, NLSF does not response ('errors in defined formula or parameter initialization) while the solver gives a convergent result. (The details of the calculation will be given as the reply of this post). So why there's a such difference? Thank you very much!


Bill

Bill Choi

Hong Kong
Posts

Posted - 10/16/2006 :  07:30:08 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
1. Equations:
The equation used in my fitting is shown in the pic as equation (6), which in my script, A=C(tot)*E(tot)



The solution of Cm is calculated according to the resources on the web http://mathworld.wolfram.com/CubicFormula.html

2. Scripts for NLSF using Origin 7.5
Parameters: Kd ('K1'), Kt ('K2'), Em, Ed, Et
Independent variable: C 'C(tot)'
Dependent variable: A

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=(3.0*b-(a^2.0))/9.0;
double R=(9.0*a*b-27.0*c-2.0*(a^3.0))/54.0;
double D=Q^3.0+R^2.0;

double t;
double S;
double T;
double Cm;
if (D<0.0)
{
t=acos(R/sqrt(-(Q^3.0)));
Cm=2.0*sqrt(-Q)*cos(t/3.0)-(a/3.0);
}
else
{
S=(R+sqrt(D))^(1.0/3.0);
T=(R-sqrt(D))^(1.0/3.0);
Cm=S+T-(a/3.0);
}
A=Cm*Em+2.0*Kd*(Cm^2.0)*Ed+3.0*Kd*Kt*(Cm^3.0)*Et;

3. Excel and Raw Data:



The sum of difference between A and A(calc) is minimized by varying K1 and K2.
Go to Top of Page

Bill Choi

Hong Kong
Posts

Posted - 10/16/2006 :  07:37:05 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Data:
C(tot)
1.00E-06
2.00E-06
3.01E-06
4.01E-06
5.01E-06
6.01E-06
7.01E-06
8.02E-06
9.02E-06
1.00E-05
1.10E-05
1.20E-05
1.30E-05
1.40E-05
1.50E-05
1.75E-05
2.00E-05

A
0.069596171
0.18049413
0.277240485
0.367668748
0.427025646
0.494419694
0.526324153
0.551330388
0.58293289
0.605690002
0.606800854
0.622256041
0.674458563
0.68992275
0.705682695
0.757495046
0.77144444

Em 115000
Ed 35361
Et 7500
K1 153819.5216
K2 130000

Calculations
a = 2/(3*K2)
b = 1/(3*K2*K1)
c = -C(tot)/(3*K2*K1)

Q = (3*b-a^2)/9
R = (9*a*b-27*c+2*a^3)/54
D = Q^3+R^2

S = (R+sqrt(D))^(1/3)
T = (R+sqrt(D))^(1/3)

Cm = S+T-a/3

The fitting is performed by minimizing the sum of difference of square between A and A(cal.).
Go to Top of Page

larry_lan

China
Posts

Posted - 10/18/2006 :  12:17:51 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Bill:

The problem is the line:

T=(R-sqrt(D))^(1.0/3.0);

You can see the result of (R-sqrt(D)) is negative, actually you can not compute power (1/3) of a negative value. In fact, the value you calculated in Excel actually is:

T=-((sqrt(D)-R)^(1.0/3.0));

Try to modify this line and fit again.

Larry
OriginLab Technical Services
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000