Author |
Topic  |
|
artem
USA
Posts |
Posted - 05/04/2006 : 5:00:58 PM
|
Origin Version (Select Help-->About Origin): Origin7.5 Operating System: win2000
Does anybody know how partial derivatives are calculated for user-defined functions in NLSF? I have a fitting function that relies on Fourier transform, so one function call is sufficient to calculate all data points in the simulated curve. Now I am trying to avoid redundant function calls and constrain calculation to only once per parameter change. The problem is that NLSF calls my Origin C program several times at each data point, using different parameters every time. From other posts at this forum, I gather that this is necessary to calculate partial derivatives numerically. However, I was not able to find any information on how these derivatives are calculated, and without that info it is hard for me to trick the program into doing what I want.
Any suggestions will be greatly appreciated Artem |
|
easwar
USA
1965 Posts |
Posted - 05/05/2006 : 11:59:30 AM
|
Hi Artem,
The fitting function code is called at each point and at each paramter change irrespective of whether derivatives are being used.
Looks like you are not interested in derivatives, but only interested in knowing how to write a part of the function that runs only on parameter change? If so, please look at this example where integration is being done only on parameter change: http://www.originlab.com/www/support/resultstech.aspx?ID=121&language=English
The trick here is to store previous paramter values and check to see if any of the paramters changed.
Easwar OriginLab [/quote]
|
 |
|
artem
USA
Posts |
Posted - 05/05/2006 : 4:06:20 PM
|
Hi Easwar,
Thank you for your quick response. I'm not sure this trick is going to work in this case though. Below is a piece of my code, very similar to the one you cited, and the results I am getting with it.
static double cstore, qstore, F1store, F2store; if ( c!=cstore || q!=qstore || F1!=F1store || F2!=F2store) { cstore=c; qstore=q; F1store=F1; F2store=F2;
int mm, nn; mm = wksY.Cell(10,1); wksY.SetCell(10,1,mm+1); // mm tells me how many times my function is calculated double curRow; LT_evaluate("nlsf.curRow", &curRow); if (curRow==1) { nn = wksY.Cell(11,1); wksY.SetCell(11,1,nn+1); } // nn tells me how many times I happen to be at row=1. // This is along the lines of the post by kfauth on 12/15/2001 // Long calculation follows
y = wksY.Cell(x,2); // This is where my function is stored } else { // When parameters were unchanged y = wksY.Cell(x,2); };
If I hit Chi-Sqr button, my function is simulated fast, and both mm and nn are equal to 1. However, when I go through one iteration it takes a long time, and also mm=410 and nn=10. My understanding is that my function is called 10 times at each point (I had 41 point in the dataset). Although that could be just a coincidence. By the way, I have four fitting parameters in my function, all unconstrained in this example.
I am not sure if there is something wrong with my code or my function is actually called multiple times at each data point, every time with different parameters to facilitate calculation of partial derivatives.
Thanks again for your help. Artem |
 |
|
easwar
USA
1965 Posts |
Posted - 05/06/2006 : 11:01:25 AM
|
Hi Artem,
The function code is called on parameter change as well as for each x value.
You need to rewrite your function, just like in the link posted before, where "only the long calculation part" is inside an if block that runs only on paramter change.
If you need more help, please send your data and your FDF to tech support.
Easwar OriginLab
|
 |
|
|
Topic  |
|
|
|