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
 Fitting function
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Sumeet kumar

India
2 Posts

Posted - 06/23/2019 :  10:01:56 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
I am trying to fit data to a function having six parameters and a constant. I entered the values of the constant and parameters to check whether the function is working or not. But I got different values from the function from Origin than from Matlab. I have attached Matlab code below in which in the lower comment, I directly copied and pasted the function written in Origin.

clear; clc;

n2 = 3;
k2 = 0.1;
n3 = 4;
k3 = 2.5;
kp = 1e-18;
t0 = 600;

lam = 1.625e-6;
t = 0;

y = 1 - abs((((1-n2)+i*k2)*((n2+n3)-i*(k2+k3))+((n2-n3)-i*(k2-k3))*((1+n2)-i*k2) ...
*exp(4*pi*sqrt(kp*(t+t0))*(-k2-i*n2)/lam))/(((1+n2)-i*k2)*((n2+n3) ...
-i*(k2+k3))+((1-n2)+i*k2)*((n2-n3)-i*(k2-k3))*exp(4*pi*sqrt(kp*(t+t0))*(-k2-i*n2)/lam)))^2

%y = 1 - abs( ( ( ( 1 - n2 ) + 1i * k2 ) * ( ( n2 + n3 ) - 1i * ( k2 + k3 ) ) + ( ( n2 - n3 ) - 1i * ( k2 - k3 ) ) * ( ( 1 + n2 ) - 1i * k2 ) * exp( 4 * pi * sqrt( kp * ( t + t0 ) ) * ( -k2 - 1i * n2 ) / lam ) ) / ( ( ( 1 + n2 ) - 1i * k2 ) * ( ( n2 + n3 ) - 1i * ( k2 + k3 ) ) + ( ( 1 - n2 ) + 1i * k2 ) * ( ( n2 - n3 ) - 1i * ( k2 - k3 ) ) * exp( 4 * pi * sqrt( kp * ( t + t0 ) ) * ( -k2 - 1i * n2 ) / lam ) ) )^2

Thanks all

Castiel

343 Posts

Posted - 06/23/2019 :  10:24:42 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by Sumeet kumar

I am trying to fit data to a function having six parameters and a constant. I entered the values of the constant and parameters to check whether the function is working or not. But I got different values from the function from Origin than from Matlab. I have attached Matlab code below in which in the lower comment, I directly copied and pasted the function written in Origin.

clear; clc;

n2 = 3;
k2 = 0.1;
n3 = 4;
k3 = 2.5;
kp = 1e-18;
t0 = 600;

lam = 1.625e-6;
t = 0;

y = 1 - abs((((1-n2)+i*k2)*((n2+n3)-i*(k2+k3))+((n2-n3)-i*(k2-k3))*((1+n2)-i*k2) ...
*exp(4*pi*sqrt(kp*(t+t0))*(-k2-i*n2)/lam))/(((1+n2)-i*k2)*((n2+n3) ...
-i*(k2+k3))+((1-n2)+i*k2)*((n2-n3)-i*(k2-k3))*exp(4*pi*sqrt(kp*(t+t0))*(-k2-i*n2)/lam)))^2

%y = 1 - abs( ( ( ( 1 - n2 ) + 1i * k2 ) * ( ( n2 + n3 ) - 1i * ( k2 + k3 ) ) + ( ( n2 - n3 ) - 1i * ( k2 - k3 ) ) * ( ( 1 + n2 ) - 1i * k2 ) * exp( 4 * pi * sqrt( kp * ( t + t0 ) ) * ( -k2 - 1i * n2 ) / lam ) ) / ( ( ( 1 + n2 ) - 1i * k2 ) * ( ( n2 + n3 ) - 1i * ( k2 + k3 ) ) + ( ( 1 - n2 ) + 1i * k2 ) * ( ( n2 - n3 ) - 1i * ( k2 - k3 ) ) * exp( 4 * pi * sqrt( kp * ( t + t0 ) ) * ( -k2 - 1i * n2 ) / lam ) ) )^2

Thanks all


abs, exp, sqrt etc. does not support complex number in Origin.
You can handle the real part and the imaginary part separately.


                                          &&&&&&&&&
                                        &&&
                                       &&
                                      &  _____ ___________
                                     II__|[] | |   I I   |
                                    |        |_|_  I I  _|
                                   < OO----OOO   OO---OO
**********************************************************
Go to Top of Page

Sumeet kumar

India
2 Posts

Posted - 06/25/2019 :  06:15:26 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks for the reply.

I got a mail from the technical team of Origin in which following suggestions were given.

If you write the fitting function in LabTalk, please use "imabs" instead of "abs", "imexp" instead of "exp".

If you write the function in OriginC, please use "cabs" instead of "abs". "exp" can work for complex number in OC.


When I implemented those changes, then it is working fine.
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