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
 Minimize using e04abc

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
tumstudent Posted - 05/28/2011 : 07:11:28 AM
Origin Ver. 8.5.0 SR1
Operating System: Win7

Hi everybody,

I have a problem (very basic I assume) using originc and specifically with the function e04abc. It wants me to input a "Function" to minimize - but what kind of object is that? It seems not to be happy when I just type in the name of a funtion that i defined as "double pwrerrfit(double x)" (see below). I'm not really sure whether a function in the context of minimization is something different from a method (as defined eg by my "double pwrerrfit(double x) {...}")

Many thanks in advance,
Max

//  Fit a powerlaw function to data and return fit results
void fitpwrwinoct(vector tfit, vector sigfit, double &x0, double &l1, double &l2)
{
// tfit, sigfit are global variables

	printf("Fit started.\n");	
	
	
	double a, b;
	double e1, e2;
	double x, f;
	int maxiter;
	Nag_Comm comm;
	static NagError fail;

	e1 = 0.0; 		
	e2 = 0.0;
	a = 0.0;						
	b = 5.0;
	maxiter = 50;
	
	e04abc(pwrerrfit, e1, e2, &a, &b, maxiter, &x, &f, &comm, &fail);
	
	// now obtain coefficients of the power law fit
	vector tx;
	tx = tfit^fitx;	
	vector vc;
	fitlinear(tx, sigfit, vc);		
	l1=vc[1]; 
	l2=vc[0]; 	
	
	x0= fitx;
	printf("Fit done.\n");
	
}




// fit a powerlaw function with exponent x to t,r data   
double pwrerrfit(double x)
{
	// tfit, sigfit are global variables
	
	vector tx;
	tx = tfit^x;
	
	vector vc;
	fitlinear(tx, sigfit, vc);
	
	vector vc0, vc1;
	int nSize = tx.GetSize();
	createConstantVector(vc[0], nSize, vc0);
	createConstantVector(vc[1], nSize, vc1);
	
	vector diff, squares;
	squares = (vc0+tx*vc1-sigfit)^2;
	double sumSquares;
	squares.Sum(sumSquares);				
	
	return sumSquares;
}
2   L A T E S T    R E P L I E S    (Newest First)
Penn Posted - 05/30/2011 : 01:31:22 AM
Hi,

I am afraid that you have the wrong call back function for the e04abc NAG function. The prototype of the right call back function for this NAG function is:

typedef void (NAG_CALL * NAG_E04ABC_FUN)(double, double *, Nag_Comm *);

So, the call back function double pwrerrfit(double x) you defined should be void NAG_CALL pwrerrfit(double x, double* fc, Nag_Comm* com). For more information about how to use NAG function, please refer to this page, please especially pay attention to Callback Functions section. Also, here includes some examples for how to access NAG functions.

Penn
tumstudent Posted - 05/28/2011 : 07:13:41 AM
Sorry, the error I get is

110525 PowerLawVarRange.c
C:\Users\Max\Desktop\E21\test power law fit\110525 PowerLawVarRange.c(269) :Error, cannot convert argument in function call
C:\Users\Max\Desktop\E21\test power law fit\110525 PowerLawVarRange.c(269) :Error, general compile error
C:\Users\Max\Desktop\E21\test power law fit\110525 PowerLawVarRange.c(248) :Error, error(s) found in compiling function fitpwrwinoct

with a pointer to the line

e04abc(pwrerrfit, e1, e2, &a, &b, maxiter, &x, &f, &comm, &fail);

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