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 for Programming
 Forum for Origin C
 Fitting Function with Parameter Ini-Code
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Burruchaga

France
4 Posts

Posted - 08/31/2017 :  10:39:07 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. 2017b9
Operating System:Win10

Dear All,

I have a problem to solve. I would like to use a fitting function with a code for parameter initilization. Well I have the code for the program ProFit and I have the fitting function, the only thing I need to do is to translate everything into Origin-C or LabTalk, but I do not know these languages. Thus, could you help me with the translation please. Here is the code:

Function NormaltitK1K2(Go,sGo,K1,K2,sHG,sHGG):real;

var z:real;


Function rac (K1,K2,z);

var dx,r,b,c,d,e:real;

begin

r:=1;

dx:=0.01;

b:=K1*K2;

c:=K1*(2*K2*z-K2*Go+1);

d:=K1*z-K1*Go+1;

e:=-Go;

while abs(dx) > 1e-10 do

begin

dx:=(r*sqr(r)*b+c*sqr(r)+d*r+e)/(3*b*sqr(r)+2*c*r+d);

r:=r-dx;

end;

rac:=r;

end;


Function F1(K1,K2,z):real;

begin

F1:=rac(K1,K2,z);

end;

Function F2(K1,K2,z):real;

begin

F2:=(z*K1*rac(K1,K2,z))/(K1*K2*sqr(rac(K1,K2,z))+K1*rac(K1,K2,z)+1);

end;

Function F3(K1,K2,z):real;

begin

F3:=(z*K1*K2*sqr(rac(K1,K2,z)))/(K1*K2*sqr(rac(K1,K2,z))+K1*rac(K1,K2,z)+1);

end;

begin

z:=x;

y:=(F1(K1,K2,z)*sGo)/Go+(F2(K1,K2,z)*sHG)/Go+(F3(K1,K2,z)*sHGG)/Go;

end;


Thanks in advance,
best regards,
Stephan

yuki_wu

896 Posts

Posted - 08/31/2017 :  11:36:15 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Stephan,

If you already defined a fitting function, I will suggest you to start with LabTalk since LabTalk may be simpler than Origin C for beginners. You should go through this page, it can help you to know this knowledge base item:
http://www.originlab.com/doc/LabTalk/guide/Non-linear-Fitting

Regards,
Yuki
OriginLab
Go to Top of Page

Burruchaga

France
4 Posts

Posted - 09/04/2017 :  09:09:56 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Dear yuki_wu,

thanks for your reply. I learned (partially^^) LabTalk. I could realize some other tasks with it, thanks for the hint.
I solved again some equations and a more accurate solution for the actual problem is of cubic character. The solutions of that equation is complex. For complex handling, origin refers to Origin C as language of choice. Well, I tried to run the calculation but, unfortunatly the result is just --. Could you explain me how to calculate a complex number with Origin C.

Here is the calculation I tried.

int test()
{

double ga = 0.01;
double ha = 0.01;
double k1 = 1000.0;
double k2 = 10000.0;


complex ci = -((k1+ga*k1*k2)/(3*k1*k2))-(2^(1/3)*(3*k1*k2-(k1+ga*k1*k2)^2))/(3*k1*k2*(-2*k1^3+9*k1^2*k2-6*ga*k1^3*k2+36*ga*k1^2*k2^2-6*ga^2*k1^3*k2^2-2*ga^3*k1^3*k2^3+sqrt((-2*k1^3+9*k1^2*k2-6*ga*k1^3*k2+36*ga*k1^2*k2^2-6*ga^2*k1^3*k2^2-2*ga^3*k1^3*k2^3)^2+4*(3*k1*k2-(k1+ga*k1*k2)^2)^3))^(1/3))+(-2*k1^3+9*k1^2*k2-6*ga*k1^3*k2+36*ga*k1^2*k2^2-6*ga^2*k1^3*k2^2-2*ga^3*k1^3*k2^3+sqrt((-2*k1^3+9*k1^2*k2-6*ga*k1^3*k2+36*ga*k1^2*k2^2-6*ga^2*k1^3*k2^2-2*ga^3*k1^3*k2^3)^2+4*(3*k1*k2-(k1+ga*k1*k2)^2)^3))^(1/3)/(3*2^(1/3)*k1*k2);
complex cc(4.5, 7.8); // Declare a complex value.
// The real component is set to 4.5 and
// the imaginary component is set to 7.8



out_double("K1 = ", k1);
out_complex("value = ", cc); // Output the complex value
out_complex("value = ", ci); // Output the complex value


return 0;

}


Thanks in advance for your help.

The result was obtained from a numeric solution from Mathematica and copying this equation with the same parameters back to Mathematica results into the same value as the intial solution (before copying and adjusting to Origin-C).

The result is:

0.000305241 + 8.67362*10^-18i

Best regards,
Stephan
Go to Top of Page

yuki_wu

896 Posts

Posted - 09/05/2017 :  05:36:01 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Stephan,

In Matlab or Mathematica, sqrt(-1) is equivalent to a basic imaginary unit; but sqrt(-1) is a missing value in Origin.

If you want to use a negative square root to get the imaginary part, define the variables ga, ha, k1 and k2 as complex instead of double:

complex ga(0.01);
complex ha(0.01);
complex k1(1000.0);
complex k2(10000.0);

Please note that since the real part and the imaginary part are the double values, the very small value will lead to overflow in calculation.

Also, use printf instead of out_complex to print the complex for small values:

printf("Real = %.15f, Img = %.15f\n", ci.m_re, ci.m_im);

For now, out_complex can only output a float value, but I have added this issue to our tracking database: ID: ORG-16964.

Hope it helps.

Regards,
Yuki
OriginLab
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