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
 Fit parameter initialization problem

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
a.abc.b35 Posted - 05/19/2011 : 6:31:34 PM
I have a strange problem. I have a fitting function, say ,
y = A*cos(x-x0)^2, where x, x0 are in radians.
.....
Now I generated a dataset, using the same function,in origin, with x from 0 to 2*PI, A =10, x0 = PI/2 and plotted it. So if I fit the above function to the graph generated from this graph, I should get A = 10 and x0 = PI/2. If I manually put any parameter and fit until converge, I do get this result !
..
Now what I did is, I set a auto initialization code as below :

#include <origin.h>
void _nlsfParamSD_cosSq(
// Fit Parameter(s):
double& A, double& x0,
// Independent Dataset(s):
vector& x_data,
// Dependent Dataset(s):
vector& y_data,
// Curve(s):
Curve x_y_curve,
// Auxilary error code: 
int& nErr)
{
	// Beginning of editable part
	//Code to be executed to initialize parameters
	vector& xcos;
	x0 = PI/2.0;
	int maxindex = x_data.GetSize();
	
	for (int i =0; i < maxindex; i++)
	{
	xcos[i] = cos(x_data[i] - x0)^2;
	}
	
	int nOrder =1;
	vector coeff;
	coeff.SetSize(nOrder+1);
	
	fitpoly(xcos,y_data,nOrder,coeff);
	
	A = coeff[1];

}


I used the fitpoly function to initialize the fit.
....
If I compile it, it compiles ok.
Now when I go the the fitting window by ctrl +Y, I would expect the fit to be almost there along with the data. But what I get is no fitted curve. And if i hit the parameter initialization button , I get the following error :
Error during compilation for parameters init. at the middle of NLFit window, just above the buttons. My initialization code will never run !! Again, if I manually put the values of A and x0 (say I put 9, 1), the code can be iterated and finally get the desired value of 10, PI/2. Can anyone tell me what's happening ? Does it have to do something with linear and non linear fit ?

AB
3   L A T E S T    R E P L I E S    (Newest First)
a.abc.b35 Posted - 05/20/2011 : 02:06:56 AM
Thanks a lot Max. So the problem was not setting the size of the vector ? Or there is more to it ? Please enlighten me. Thanks again.

AB
minimax Posted - 05/20/2011 : 01:51:17 AM
Hi AB,

The init code needs a bit modification.


{
	// Beginning of editable part
	//Code to be executed to initialize parameters
	vector xcos;
	x0 = PI/2.0;
	int maxindex = x_data.GetSize();
	xcos.SetSize(maxindex);
	for (int i =0; i < maxindex; i++)
	{
	xcos[i] = cos(x_data[i] - x0)^2;
	}
	
	int nOrder =1;
	vector coeff;
	coeff.SetSize(nOrder+1);
	
	fitpoly(xcos,y_data,nOrder,coeff);
	
	A = coeff[1];

}


Max
OriginLab Technical Support
a.abc.b35 Posted - 05/19/2011 : 8:06:41 PM
By the way, I get the same error in Origin 8 SR6 also !

AB

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