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
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Fitting Function containing a summation/Sigma-Sign

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
Lenchen Posted - 03/01/2017 : 07:13:12 AM
Origin Ver. and Service Release (Select Help-->About Origin):
Operating System: OriginPro 2016G

Hi,
I'm triying to build a fit function with Origin C which includes a summation function like

y(x,D,kD,kR)=D*a(x,kD)+(1-D)*(1-exp(-kR*x))

with a(x,kD)=Σ(n=1 --> 100)((1/n^2)*exp(-n^2*kD*x))

(Dependent Variable: y, Independent Variable: x, Fit-Parameter: D,kD,kR)

How can I define the summation function a(x,kD) and how do I summarize the functions a_1(x,kD), a_2(x,kD) .... a_100(x,kD)?

Thank you very much for helping me :-)
7   L A T E S T    R E P L I E S    (Newest First)
yuki_wu Posted - 03/15/2018 : 03:34:32 AM
Hi Elisa,

I think you hope to define a function like this:
function double function1(double x, double A, double B, double C, double k, double k2, double k3, double x0, double xt, int n)
{
	double y0 = A*(1-exp(-k*x))+B*(exp(k2*(x-x0)-1));
	double bb = 0;
	for(ii = 1; ii <= n; ii++)
	{
		bb = (1-8/((2*ii+1)^2*PI^2)*exp(-k3*(2*ii+1)^2*PI^2*(x-xt)))+ bb;
	}
	bb = C * bb;
	return bb + y0; 
}


BTW, you could also take a look at the LabTalk Function base item, it could help you to understand the modification:
https://www.originlab.com/doc/LabTalk/guide/Functions

Regards,
Yuki
OriginLab
sisa12 Posted - 03/14/2018 : 06:06:40 AM
Hello everybody, i'm also struggling to insert a summation in my fitting function. I follow the procedure described by Yuki here https://my.originlab.com/forum/topic.asp?TOPIC_ID=28114 and here: https://my.originlab.com/forum/topic.asp?TOPIC_ID=22659

but when i try to use the fitting function i get the error Unknown function:funct1.

Here the function i want to write:
y=A*(1-exp(-k*x))+B*(exp(k2*(x-x0)-1))+C*(1-∑_(i=1-n)8/((2*ii+1)^2*PI^2)*exp(-k3*(2*ii+1)^2*PI^2*(x-xt)

I put:
Independent Variables: x
Dependent Variables: y
Parameter Names: A,B,k,k2,x0,C,k3,xt,n
Function Form: Expression

I fixed n=1000

Function edit box:
funct1(x, A,B;C,k,k2,k3,x0,xt,n)

Labtalk function definition and initialization:

function y0 (double A, double B, double x, double k, double k2, double x0)

y0=A*(1-exp(-k*x))+B*(exp(k2*(x-x0)-1))

function double funct1(double x, double k3, double xt, int n)
{
double bb = y0;
for(ii =1; ii<=n; ii++)
{
bb = C(1-8/((2*ii+1)^2*PI^2)*exp(-k3*(2*ii+1)^2*PI^2*(x-xt)))+ bb;
}
return bb;
}

Could anyone help me with this? thank you very much.

Elisa Bindini
yuki_wu Posted - 06/23/2017 : 05:11:46 AM
Hi all,

I camp up this very simple example only for showing how to define a fitting function with a summation. I am sorry that I only checked its simulation at that time, but did not take into account the fitting part.

If you unfortunately find that fit did not converge when you have this user-defined function, please take a look at this post:
http://www.originlab.com/forum/topic.asp?TOPIC_ID=31355

Regards,
Yuki
OriginLab
Lenchen Posted - 03/02/2017 : 04:50:56 AM
Thanks a lot, it works
yuki_wu Posted - 03/02/2017 : 03:00:07 AM
Hi,

In my previous post, you should set these items as follow:

Independent Variables: x
Dependent Variables: y
Parameter Names: n
Function Form: Equations
Function: y = sum(x, n)
LabTalk Functions Definition and Initializations:
function double sum(double x, double n)
{
    double bb = 0;
    for(ii =1; ii<=n; ii++)
    {
    	bb = ii * x * x + bb;
    }
    return bb;
}


If you want to define the function in Origin C type:

Independent Variables: x
Dependent Variables: y
Parameter Names: n
Function Form: Origin C
Function:
1) Click the button next to Function box to open Code Builder
2) Edit the function:
void _nlsfsummation(
// Fit Parameter(s):
double n,
// Independent Variable(s):
double x,
// Dependent Variable(s):
double& y)
{
    // Beginning of editable part
    double bb = 0;
    for(int ii =1; ii<=n; ii++)
    {
	 bb = ii * x * x + bb;
    }
    y = bb;
    // End of editable part
}


Hope I make it clear.

Regards,
Yuki
OriginLab
Lenchen Posted - 03/02/2017 : 02:09:22 AM
Hi,
thank you very much for your kind reply.
Unfortunatly, I know very little about programming and still cannot compile the example function. I am using the fitting function builder with Origin C as function type. Settings:

x independent variable
y dependent variable
n paramter

Then I inserted y = sum(x, n) into the function body, but could not move on in the dialog (makes sense to me, nothing is defined yet). So I put the definition of the function sum beneath it:

function double sum(double x, double n)
{
double bb = 0;
for(ii =1; ii<=n; ii++)
{
bb = ii * x * x + bb;
}
return bb;
}

But still I got an error when trying to compile.
I also tried other function types and tried to insert the definition of the function sum into other fields, but without any success.

So my question is: where and how do I define the definition of the function sum, and do I need to define other variables like bb or ii? Or did Ido everything in the wrong way?

Thank you!
yuki_wu Posted - 03/01/2017 : 9:59:35 PM
Hi,

You can define the fitting function with an embedded For loop in the function definition box. Take the following function as an example.


Suppose you define the fitting function in the Function box as follow:
y = sum(x, n)

Then define functions sum as follow:

function double sum(double x, double n)
{
    double bb = 0;
    for(ii =1; ii<=n; ii++)
    {
    	bb = ii * x * x + bb;
    }
    return bb;
}

Hope it helps.

Regards,
Yuki
OriginLab

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000