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
 Taking derivatives of functions in Origin C

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
gpoon Posted - 07/21/2009 : 2:31:06 PM
Origin Ver. 8 and Service Release (Select Help-->About Origin): SR4
Operating System: XP

I am trying to take numerical derivatives of functions (not a dataset of points) in Origin C. I noticed that the NAG library doesn't have a function for differentiation for C (but does for Fortran). The GNU Scientific Library (GSL) does have such a function, but I cannot get it to work because, apparently, Origin C doesn't support calling external functions that return a struct type variable.

So this is what I was trying in my "ocgsl.h" file:

/* Definition of an arbitrary function with parameters */

struct gsl_function_struct
{
double (* function) (double x, void * params);
void * params;
};

typedef struct gsl_function_struct gsl_function ;

GSL_EXPORT int gsl_diff_central (const gsl_function *f,
double x,
double *result, double *abserr);

Does Origin C (or NAG) have a differentiation function (for functions) that I just don't know about? Is there any way to overcome this limitation of calling functions that return struct type variables? Many thanks!
4   L A T E S T    R E P L I E S    (Newest First)
gpoon Posted - 07/27/2009 : 02:16:46 AM
It works! Thanks!
Iris_Bai Posted - 07/22/2009 : 11:36:09 PM
Hi Gregory,

Please try the following way to define a function pointer outside strcut:

typedef double (* FUNC)(double x, void * params);

struct gsl_function_struct
{
	FUNC function;
	void * params;
};


Iris
gpoon Posted - 07/22/2009 : 6:04:23 PM
Hi Iris!

Thanks for your reply. When I tried to compile "ocgsl.h" as follows (using the example on OriginWiki was a template):

#pragma dll(libgsl, header)
// this is OC special pragma,
// header keyword is to indicate libgsl.dll is in same location as this file

#define GSL_EXPORT // for OC, this is not needed, so make it empty

// you can directly search and copy gsl function prototypes here

struct gsl_function_struct
{
double (* function) (double x, void * params); <---
void * params;
};

typedef struct gsl_function_struct gsl_function ;

GSL_EXPORT int gsl_diff_central (const gsl_function *f,
double x,
double *result, double *abserr);

The compiler returns "Error, syntax error in function declaration" at the line marked with the arrow. What is my mistake?

Thanks,
Gregory
Iris_Bai Posted - 07/21/2009 : 11:39:55 PM
Hi,

Could you give more details about not work, for example compiling error?
Origin C doesn't support external functions that return a struct type variable, but support struct type as output variable. In your code above, gsl_function is a struct and in gsl_diff_central function it is a output variable, not a return value. So should work in Origin C.

Any way, you can reference to:
http://wiki.originlab.com/~originla/internal/index.php?title=Tutorial:Fitting_with_Integral_Function_using_GSL_routine

http://ocwiki.originlab.com/index.php?title=OriginC:Calling_GNU_Scientific_Library



Iris

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