Author |
Topic |
|
brian0918
USA
6 Posts |
Posted - 07/20/2004 : 11:24:23 PM
|
I'm trying to call the built-in Peak function ECS in a user-defined function, as described here: http://www.originlab.com/www/support/resultstech.aspx?ID=253&language=English
It gives the error "Unable to compile user defined function," even if I simply call the ECS function, without adding anything else:
Parameter Names: y0,xc,A,w,a3,a4 Independent Var.: x Dependent Var.: y
y = ECS(x,y0,xc,A,w,a3,a4);
This will not even work, giving the error mentioned above, even if I give it initial parameter values that are known to be the actual fit of the data, were I to use the built-in ECS function. (I've tried it with and without the semicolon)
Any suggestions?
Version: Origin 7.5 SR0 v7.5714 (B714)
(The option "Use Origin C" is checked, while "Derivatives" is not) |
|
Mike
USA
357 Posts |
Posted - 07/21/2004 : 10:18:18 AM
|
Using 7.5 SR0, I created a "user-defined" function using the following expression (no semi-colon):
ecs(x,y0,xc,A,w,a3,a4)
I unchecked the Use Origin C checkbox, set the Form drop down to Expression, and entered the following parameter names: y0,xc,A,w,a3,a4
After entering some parameter estimates, I was able to fit. So, I would start by unchecking the Use Origin C checkbox.
Mike OriginLab
|
|
|
brian0918
USA
6 Posts |
Posted - 07/21/2004 : 10:31:49 AM
|
I noticed that it does seem to work for Expression, but it took about a minute to do just 1 iteration, while the original ECS built-in function could do 100 iterations in about 5 seconds.
Is it normal for Expression to be that much slower, and is there any other way that it could be done?
Thanks. |
|
|
easwar
USA
1964 Posts |
Posted - 07/21/2004 : 2:17:58 PM
|
Hi,
When you switch to a function type other than Origin C (such as Y-Script, Expression etc with Origin C check box unchecked), Origin uses LabTalk script for the function. Script is much slower - the function text is repeatedly interpreted etc.
Even though you are only referring to the internal fit function in your script, your function is still defined in script and it will run slower. Typically script is about 20 times slower than Origin C.
Now there was a way to access the built-in functions from Origin C code, which worked in Origin 7 (SR2) but appears to have been not working since. The way was to refer to the function by name, but with "nls" prefixed to the name, such as: y = nlsECS(x, y0, xc...)
We need to fix this bug. For now you would need to continue use script. Our apologies for the inconvenience.
Easwar OriginLab
Edited by - easwar on 07/21/2004 2:18:58 PM |
|
|
brian0918
USA
6 Posts |
Posted - 07/21/2004 : 3:06:11 PM
|
Do you know what other versions, besides 7, that this feature worked in? I may be able to get ahold of older versions through my school, if necessary. (version 6, for example) |
|
|
Mike
USA
357 Posts |
Posted - 07/21/2004 : 3:48:27 PM
|
Hi brian0918,
I think we have a workaround for you. Since Origin 7, you should have been able to call a built-in function within a user-defined function in the NLSF using the following syntax (as for example):
y=nlfxGauss(x,y0,x0,w,A)
Unfortunately, this was broken sometime subsequent to the 7.0 SR2 release. The problem has something to do with the arguments between the parentheses not being used before they appear when the function is called. So if you add something like line 1 in this example, before calling the function on line 2 ...
double junk = x + y0 + xc + A + w + a3 + a4;// to avoid arg checking bug y = nlfxECS(x,y0,xc,A,w,a3,a4);
... then, you should be able to compile the function.
Let us know how you do.
Mike OriginLab
Edited by - Mike on 07/21/2004 4:07:18 PM
Edited by - Mike on 07/21/2004 4:22:48 PM |
|
|
brian0918
USA
6 Posts |
Posted - 07/21/2004 : 4:49:26 PM
|
Thanks for the reply. I won't be able to try this for several more hours, but I'll let you know.
What I'm trying to do is add something onto the ECS function to fit a curve better. I'm not sure what will work, but it can only be one parameter, or, at most, two.
I have been trying to create my own functions on Origin, before I knew that built-in functions could be called, and the fitting would never work. I gave it the function, and the partial derivatives, checked "Derivatives," etc... But whenever I would try to do even one iteration, it would always get stuck trying to "compute a curvature matrix" and never get any further, even on the simplest of functions.
So I tried the same thing with ECS, worked out all the partial derivatives (several lines each), and tried putting it in, but it would still get caught at the same spot.
No clue what the problem is, but if I can get this work, I won't have to worry about any of that.
Thanks.
|
|
|
Mike
USA
357 Posts |
Posted - 07/21/2004 : 5:14:50 PM
|
Hi brian0918,
It sounds as though you've already done a considerable amount of "head-banging" over this. Rather than do any more, how about sending your .FDF file(s) (they are in your \FitFunc folder) along with a sample data set to tech@originlab.com ? Be sure to refer to this thread in your e-mail. Thanks.
Mike OriginLab |
|
|
brian0918
USA
6 Posts |
Posted - 07/21/2004 : 10:53:19 PM
|
I tried what you said:
Parameter Names: y0,xc,A,w,a3,a4
Independent Var: x
Dependent Var: y
double junk = x + y0 + xc + A + w + a3 + a4; y = nlfxECS(x,y0,xc,A,w,a3,a4);
If I edit this in Code Builder, and compile it as is, I get this:
void _nlsfECS_extra( // Fit Parameter(s): double y0, double xc, double A, double w, double a3, double a4, // Independent Variable(s): double x, // Dependent Variable(s): double& y) { // Beginning of editable part double junk = x + y0 + xc + A + w + a3 + a4; y = nlfxECS(x,y0,xc,A,w,a3,a4); // End of editable part }
compiling... _nlfECS_extra.fit FEEDBACK macros not defined Done!
Derivatives is not checked, but Use Origin C is checked.
I gave it initial values, tried 1 iteration, and as always, it just sat there, saying this in the bottom left corner:
"Computing curvature matrix at iteration 1"
Any suggestions?
|
|
|
Mike
USA
357 Posts |
Posted - 07/22/2004 : 10:13:33 AM
|
Okay, so it compiled (ignore the macros warning), but it is still hanging somehow.
Please see my previous post. If you can send your fitting function and a sample data set, we would be happy to look at it and try to sort out what is happening.
Also.... can I get you to send us your initial parameter estimates?
Thanks.
Mike OriginLab
Edited by - Mike on 07/22/2004 11:15:25 AM |
|
|
brian0918
USA
6 Posts |
Posted - 07/22/2004 : 1:12:53 PM
|
I have sent an email to tech@originlab.com entitled:
For Michael Genthner: Calling built-in functions in user-defined fnctns |
|
|
|
Topic |
|
|
|