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
 Non linear regression of summation
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

MantaManni

Germany
9 Posts

Posted - 08/07/2020 :  06:48:50 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
OriginPro 2020 (64-bit) SR1
9.7.0.188 (Academic)


Hello together,

I am trying to implement a summation equation to OriginPro, but since I am not into programming at all, I guess someone here can help me with this.

So my equation is:



I managed to implement "standard" equations in the format y=mx+b, but since there is a summation occuring I have no clue how to handle with that,
I already read that it was somehow possible with origin C, but I don't know how since I have no big mathematical but more a biological background.

Thank you very much in advance

Edited by - MantaManni on 08/07/2020 06:51:43 AM

Chris D

428 Posts

Posted - 08/07/2020 :  10:22:05 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You may refer to this forum post for some detailed information and insight into the subject:
https://my.originlab.com/forum/topic.asp?TOPIC_ID=28114

Thanks,
Chris Drozdowski
Originlab Technical Support
Go to Top of Page

YimingChen

1669 Posts

Posted - 08/07/2020 :  1:50:37 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Please also check this tutorial page on fitting summation of infinite series. You will need to set a precision value.
https://www.originlab.com/doc/Tutorials/Fitting-Summation

James
Go to Top of Page

YimingChen

1669 Posts

Posted - 08/07/2020 :  3:45:11 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Would you mind sending your data and parameter guesses to <tech@originlab.com> that we can check further? Thank you.

James
Go to Top of Page

MantaManni

Germany
9 Posts

Posted - 08/10/2020 :  07:57:57 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
So I finally managed to get the equation run.

It looks like this:

double bb=0;
double ga=-D*(2*n+1)^2*pi^2*x/(4*L^2);
double f=(2*n+1)*pi/(2*L);

for(int ii =0; ii<=n; ii++)
{
if(floor(n)==ii)
bb = exp(ga)*(f*exp(-2*g*L)+(-1)^n*(2*g))/((2*n+1)*(4*g^2+f^2)) + bb;
else
bb = exp(ga)*(f*exp(-2*g*L)+(-1)^ii*(2*g))/((2*ii+1)*(4*g^2+f^2)) + bb;
}
y = (1-(8*g/pi*(1-exp(-2*g*L)))*bb)*Aeq;


Here are my fitted data:



Unfortunately the fit always starts at y<1 which I don't expect since I want to start it at y=0

Do you have any guesses to get a better fit at all?
Go to Top of Page

YimingChen

1669 Posts

Posted - 08/10/2020 :  09:56:38 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You can force the fitted line go through (0,0) point. You can set a large weight for the data point. See this page:
https://www.originlab.com/doc/Tutorials/Fitting-FixThroughPoint#Use_weighting

James
Go to Top of Page

YimingChen

1669 Posts

Posted - 08/10/2020 :  11:47:23 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Also in your oc code, ga and f should be defined inside for loop, as both has n that needs to be iterated.

James
Go to Top of Page

YimingChen

1669 Posts

Posted - 08/10/2020 :  3:15:14 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
If I set n to a large value 100 as constant, and put ga, f inside for loop:

double bb=0;

for(int ii =0; ii<=n; ii++)
{		
	double ga=-D*(2*ii+1)^2*pi^2*x/(4*L^2);
	double f=(2*ii+1)*pi/(2*L);
	bb = exp(ga)*(f*exp(-2*g*L)+(-1)^ii*(2*g))/((2*ii+1)*(4*g^2+f^2)) + bb;
}
y = (1-(8*g/pi*(1-exp(-2*g*L)))*bb)*Aeq;


The fitted line does start from original point.


James
Go to Top of Page

MantaManni

Germany
9 Posts

Posted - 08/11/2020 :  05:30:31 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you so much!
Even though I still don't understand the mathematical background, why now the line starts at the initial value :D

Unfortunately this equation is shown and used in many publications for determining Diffusion coefficients, but none of the reports specified n. So I don't actually know which value for n is "correct"
Go to Top of Page

MantaManni

Germany
9 Posts

Posted - 08/17/2020 :  11:53:48 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi all

I have a new equation with 2 sums this time.
I tried my best, but can't find the error. My data is not fitting at all.






void _nlsfDiffusionsumbeta(
// Fit Parameter(s):
double D, double alp, double CSeq, double q, double Dst, double Ka,
// Independent Variable(s):
double x,
// Dependent Variable(s):
double& y)
{
const double m=10;
const double n=10;
const double l=0.000555;
const double g=13100;
// Beginning of editable part
double bb=0;
double cc=0;
double K=sqrt(q/D);
double Aeq=(CSeq/2*g)*(1-exp(-2*g*l));

for(int ii =0; ii<=n; ii++)
{
double ga=((2*ii+1)^2*pi^2*D)/(4*l^2);
double f=((2*ii+1)*pi)/(2*l);
bb = exp(-ga*x)*((-1)^ii*2*g+f*exp(-2*g*l))/((2*ii+1)*(4*q*l^2-D*pi^2*(2*ii+1)^2)*(4*g^2+f^2)) + bb;
}

for(int jj =0; jj<=m; jj++)
{
cc = ((((2*jj+1)*pi/2*l)*exp(-2*g*l)+(-1)^jj*2*g)/((4*g^2+((2*jj+1)*pi)/2*l)^2)*(2*jj+1))*exp(-1*(2*jj+1)^2*Dst*x) + cc;
}

y=(alp*(1-((8*g)/(pi*(1-exp(-2*g*l))))*cc)+(1-alp)*(1-((2*g*(exp(-2*g*l)*(2*g*cos(K*l)-K*sin(Ka*l))-2*g)/(1-exp(-2*g*l))*(4*g^2+K^2)*cos(K*l))*(exp(-q*x))*((32*q*l^2*g)/(pi*(1-exp(-2*g*l)))))*bb))*Aeq
// End of editable part
}


Maybe it is too obvious to see, and maybe someone can solve the problem :D

Edited by - MantaManni on 08/17/2020 11:55:30 AM
Go to Top of Page

YimingChen

1669 Posts

Posted - 08/18/2020 :  4:57:44 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Two things you might want to double check:
1. Is D same as Dst?
2. Is K same as Ka?

James
Go to Top of Page

MantaManni

Germany
9 Posts

Posted - 08/25/2020 :  05:22:57 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Well it didn't work anyway for my data.

but how would you solve this equation in origin c?
Go to Top of Page

YimingChen

1669 Posts

Posted - 08/25/2020 :  09:16:26 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You can use Equation Solver app to solve a = b_n*tan(b_n).
https://www.originlab.com/FileExchange/details.aspx?fid=393

But the app won't work for equation 7 with summation in it.

James
Go to Top of Page

MantaManni

Germany
9 Posts

Posted - 08/28/2020 :  11:20:44 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Is there a way to define the beta_n positive roots in origin C?

Or better:

Can you give me a origin C script for this simplified equation?


That would be amazing! I really can't figure out how to only get the positive roots for ß_n.

Thank you very much in advance!

Edited by - MantaManni on 08/28/2020 3:10:52 PM
Go to Top of Page

YimingChen

1669 Posts

Posted - 08/31/2020 :  10:03:45 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

the equation can't be solved analytically. We can probably give an approximate numerical solution. Please email the fitting function and data to <tech@originlab.com>.

James
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