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
 Origin Forum
 Heaviside function (Step Function)

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
Estitxu Posted - 07/30/2013 : 09:56:15 AM
Hi I'm Working with Origin 8 and I wonder if the Heaviside Function (also called step function) is defined there, since I don't find it.

Thanks a lot!!
4   L A T E S T    R E P L I E S    (Newest First)
Estitxu Posted - 08/01/2013 : 11:39:26 AM
Sorry I forgot to tell: V is the independent variable of the function (x).
Estitxu Posted - 08/01/2013 : 11:37:05 AM
Hi,

first of thanks for your help!

Actually, what I need to do is a bit complicated... I need to fit an integral function, which inside the integrand has a Heaviside function. The function is the following:



I tried defining the step function in both ways you told me, but I have some compilation errors which I don't know where they come from! I used the following two codes:

CODE 1:

#pragma warning(error : 15618)
#include <origin.h>
#include <oc_nag8.h>
#define NAG_FREE(X) x04bdc((Pointer *)&(X))


// Add your special include files here.
// For example, if you want to fit with functions from the NAG library,
// add the header file for the NAG functions here.

// Add code here for other Origin C functions that you want to define in this file,
// and access in your fitting function.

struct user
{
double e, EF, KT, Vb, fitX; // fitX the independent variable of fitting function
double x0=EF-e*x+e*Vb;
double step(double FitX, double x0) {
return (fitX<x0?0:(fitX==x0?1:1));
}

};
static double NAG_CALL f_callback(double x, Nag_User *comm) // x is the independent variable of the integrand
{

struct user *sp = (struct user *)(comm->p);

double ee, EE, KK, VV, fitX; // temp variable to accept the parameters in the Nag_User communication struct
e= sp->e;
EF = sp->EF;
KT = sp->KT;
Vb = sp->Vb;
x0 = sp->x0;
fitX = sp->fitX;



return (1/(1+exp(fitX/KT))-1/(1+exp((fitX-e*x)/KT)))*step(fitX,x0);
}



// You can access C functions defined in other files, if those files are loaded and compiled
// in your workspace, and the functions have been prototyped in a header file that you have
// included above.

// You can access NLSF object methods and properties directly in your function code.

// You should follow C-language syntax in defining your function.
// For instance, if your parameter name is P1, you cannot use p1 in your function code.
// When using fractions, remember that integer division such as 1/2 is equal to 0, and not 0.5
// Use 0.5 or 1/2.0 to get the correct value.

// For more information and examples, please refer to the "User-Defined Fitting Function"
// section of the Origin Help file.


//----------------------------------------------------------
//
void _nlsfnag_integration_marco(
// Fit Parameter(s):
double e, double EF, double KT, double R, double Vb,
// Independent Variable(s):
double x, double It,
// Dependent Variable(s):
double& y)
{
// Beginning of editable part
double epsabs = 0.00001, epsrel = 0.0000001, result, abserr;
Integer max_num_subint = 500;
// you may use epsabs and epsrel and this quantity to enhance your desired precision
// when not enough precision encountered

Nag_QuadProgress qp;
static NagError fail;

// the parameters parameterize the integrand can be input to the call_back function
// through the Nag_User communication struct
Nag_User comm;
struct user s;
s.e = e;
s.EF = EF;
s.KT = KT;
s.Vb = Vb;
s.fitX = x;
comm.p = (Pointer)&s;

d01sjc(f_callback, Nag_LowerSemiInfinite, Nag_UpperSemiInfinite, epsabs, epsrel, max_num_subint, &result, &abserr, &qp, &comm, &fail);


// you may want to exam the error by printing out error message, just uncomment the following lines
// if (fail.code != NE_NOERROR)
// printf("%s\n", fail.message);


// For the error other than the following three errors which are due to bad input parameters
// or allocation failure NE_INT_ARG_LT NE_BAD_PARAM NE_ALLOC_FAIL
// You will need to free the memory allocation before calling the integration routine again to
// avoid memory leakage
if (fail.code != NE_INT_ARG_LT && fail.code != NE_BAD_PARAM && fail.code != NE_ALLOC_FAIL)
{
NAG_FREE(qp.sub_int_beg_pts);
NAG_FREE(qp.sub_int_end_pts);
NAG_FREE(qp.sub_int_result);
NAG_FREE(qp.sub_int_error);
}


y = R*It*result;
// note use log of the integral result as return as the integral result is large,
// you are not necessary to do so
// End of editable part
}






CODE 2:

#pragma warning(error : 15618)
#include <origin.h>
#include <oc_nag8.h>
#define NAG_FREE(X) x04bdc((Pointer *)&(X))


// Add your special include files here.
// For example, if you want to fit with functions from the NAG library,
// add the header file for the NAG functions here.

// Add code here for other Origin C functions that you want to define in this file,
// and access in your fitting function.

struct user
{
double e, EF, KT, Vb, fitX; // fitX the independent variable of fitting function


};
static double NAG_CALL f_callback(double x, Nag_User *comm) // x is the independent variable of the integrand
{

struct user *sp = (struct user *)(comm->p);

double ee, EE, KK, VV, fitX; // temp variable to accept the parameters in the Nag_User communication struct
ee = sp->e;
EE = sp->EF;
KK = sp->KT;
VV = sp->Vb;
fitX = sp->fitX;

return

{ if(fitX<EE-ee*x+ee*VV) {
return 0;
} else {
return (1/(1+exp(fitX/KK))-1/(1+exp((fitX-ee*x)/KK)));
}
}
}


// You can access C functions defined in other files, if those files are loaded and compiled
// in your workspace, and the functions have been prototyped in a header file that you have
// included above.

// You can access NLSF object methods and properties directly in your function code.

// You should follow C-language syntax in defining your function.
// For instance, if your parameter name is P1, you cannot use p1 in your function code.
// When using fractions, remember that integer division such as 1/2 is equal to 0, and not 0.5
// Use 0.5 or 1/2.0 to get the correct value.

// For more information and examples, please refer to the "User-Defined Fitting Function"
// section of the Origin Help file.


//----------------------------------------------------------
//
void _nlsfCopyOfnag_integration_marco(
// Fit Parameter(s):
double e, double EF, double KT, double R, double Vb,
// Independent Variable(s):
double x, double It,
// Dependent Variable(s):
double& y)
{
// Beginning of editable part
double epsabs = 0.00001, epsrel = 0.0000001, result, abserr;
Integer max_num_subint = 500;
// you may use epsabs and epsrel and this quantity to enhance your desired precision
// when not enough precision encountered

Nag_QuadProgress qp;
static NagError fail;

// the parameters parameterize the integrand can be input to the call_back function
// through the Nag_User communication struct
Nag_User comm;
struct user s;
s.e = e;
s.EF = EF;
s.KT = KT;
s.Vb = Vb;
s.fitX = x;
comm.p = (Pointer)&s;

d01sjc(f_callback, Nag_LowerSemiInfinite, Nag_UpperSemiInfinite, epsabs, epsrel, max_num_subint, &result, &abserr, &qp, &comm, &fail);


// you may want to exam the error by printing out error message, just uncomment the following lines
// if (fail.code != NE_NOERROR)
// printf("%s\n", fail.message);


// For the error other than the following three errors which are due to bad input parameters
// or allocation failure NE_INT_ARG_LT NE_BAD_PARAM NE_ALLOC_FAIL
// You will need to free the memory allocation before calling the integration routine again to
// avoid memory leakage
if (fail.code != NE_INT_ARG_LT && fail.code != NE_BAD_PARAM && fail.code != NE_ALLOC_FAIL)
{
NAG_FREE(qp.sub_int_beg_pts);
NAG_FREE(qp.sub_int_end_pts);
NAG_FREE(qp.sub_int_result);
NAG_FREE(qp.sub_int_error);
}


y = R*It*result;
// note use log of the integral result as return as the integral result is large,
// you are not necessary to do so
// End of editable part
}








Do you know what's wrong? Or do you know how I could improve them?? (of course it's enough with one of them as long as it works ;) )

Thanks a lot!!
Hideo Fujii Posted - 07/30/2013 : 1:53:41 PM
Hi,

If you only need a scalar function to use in Set Column Values tool), you can make and compile the following 1-line Origin C code:
double step(double x, double x0, double c) {
	return (x<x0?0:(x==x0?c:1));
}
where x0 is the x offset (typically 0), and c is the y value at x0 (typically 0.5 or 0).

--Hideo Fujii

P.S. If you use the step function for fitting, I found that the x0(x offset) initial parameter value should be in between the left and right sides of the step to lead the successful convergence. To find such value, you can first try continuous sigmoidal function like Boltzmann .
meili_yang Posted - 07/30/2013 : 10:26:49 AM
Hi Estitxu,

I guess it's not included in Origin yet. You will need to create user-defined function. There are some discussions about fitting with step function or Heaviside function in previous posts. For example http://www.originlab.com/forum/topic.asp?TOPIC_ID=8200

You can search on others as well.

All the best,


Meili
OriginLab Tech Support

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