Author |
Topic |
|
jcermex
Posts |
Posted - 10/11/2007 : 11:20:33 AM
|
Origin Version (Select Help-->About Origin): OriginPro 7.5 SR0 Operating System: XP sp2 I am using Non-linear Curve Fit. I have a sort of number: X Y -30 150 -24 100 -21 70 -18 50 -16 40 -13 30 -11 20 -8 10 8 10 11.5 20 14 30 17 40 18 50 22 70 26 100 30 150
I want to fit the number into the function as follows y=((2*0.99E-3)/632.8E-9)*(1-n-cos(x-a)+sqrt(n2-(sin(x-a))2))
n, a are the parameters. Initial values are 1.5 and 0.5
I do the following steps:
1 Create the worksheet with the values 2 Plot a graph in the form of scatter points 3 Select Analysis-->Non-linear Curve Fit--> Advanced Fitting Tool 4 In the NLS window, Select Category--> New, choose a name, Next Select Funtion--> New, choose a name and also numbers of parameters, define expression. Finally Select Save. 5 After that Select Action--->Dateset, assign variables. 6 Select Action--> fit and slect 1iter
After all, a window appears with the following message: Unable to compile user defined function.
Could you help me?
Thanks.
|
|
Mike Buess
USA
3037 Posts |
Posted - 10/11/2007 : 12:46:20 PM
|
I see errors in your function...
y = (2*0.99E-3/632.8E-9) * (1 - n - cos(x-a) + sqrt( n2 - sin(x-a) ) operator 2 ) )
1. Is n2 a third parameter or are you missing an operator between n and 2?
2. You also need to supply the operator.
Mike Buess Origin WebRing Member |
|
|
jcermex
Posts |
Posted - 10/17/2007 : 08:22:28 AM
|
sorry, this is the correct equation:
y=((2*0.99E-3)/632.8E-9)*(1-n-cos(x-a)+sqrt((n^2)-(sin(x-a))^2))
Thanks
|
|
|
Mike Buess
USA
3037 Posts |
Posted - 10/17/2007 : 12:15:22 PM
|
The corrected function compiles fine but will not fit your data because the x values are in degrees and the OriginC cos(x) and sin(x) functions expect x to be in radians. I cleaned up the function and converted x to radian in the top figure and fitted your data quite nicely at bottom.
NLSF function definition:
Fit to data:
Mike Buess Origin WebRing Member |
|
|
jcermex
Posts |
Posted - 10/18/2007 : 05:38:11 AM
|
Dear Mike, I followed all the steps and Its impossible to fit,The same message appears Unable to compile user defined function
What is the problem in origin? Do I need to defined another things? or maybe Its a problem with the configuration in origin
Thanks |
|
|
Mike Buess
USA
3037 Posts |
|
jcermex
Posts |
Posted - 10/24/2007 : 12:01:11 PM
|
Dear Mike, I did the uptodate and I still problems with the fit. Do you tink i need to change somthing in Origin to get good fitting?
Thanks.
|
|
|
Mike Buess
USA
3037 Posts |
Posted - 10/24/2007 : 10:39:54 PM
|
quote: I still problems with the fit
That's pretty vague, but if the problem lies in using (not compiling) the function then it's probably a matter of parameter initialization. For your data the parameter a is clearly close to zero, but if you start out with a=0 and n=1 and vary both parameters the fit ends up somewhere far off in parameter space where a>>1 and n~1. Instead, start out with those initial values but iterate a few times varying only n until the value of that parameter no longer changes. Then vary a as well and both parameters will soon reach reasonable values.
Note: The unit of parameter a is radian as I defined the function earlier in this thread. If you want a in degrees you can either convert after fitting or define the function like this...
double y0 = 2.0 * 0.99E-3 / 632.8E-9; double x0 = (x - a) * pi / 180.0; y = y0 * ( 1.0 - n - cos(x0) + sqrt( n^2 - sin(x0)^2 ) );
Mike Buess Origin WebRing Member |
|
|
flirt
USA
Posts |
Posted - 11/06/2007 : 12:44:09 PM
|
This is because you did not define the parameters properly. should check "user defined parameters" and enter the parameters in the "parameter names", check "use origin c", click save and "edit in codebuilder", compile there and it will pass. The equation you gave will not fit because x should be transformed into arc. I add another parameter: y=((2*0.99E-3)/632.8E-9)*(1-n-cos(b*(x-a))+sqrt((n^2)-(sin(b*(x-a)))^2)), it fits pretty well.
|
|
|
rajintha
USA
Posts |
Posted - 03/12/2010 : 2:25:46 PM
|
This reply might be a couple of years late. However, for Origin 7 users who might find them selves at this page due a similar error, the issue could also be a problem with your default printer driver. More details at:
http://www.originlab.com/forum/topic.asp?TOPIC_ID=6143 |
|
|
berts
France
4 Posts |
Posted - 04/17/2010 : 3:16:16 PM
|
Hello!
Could anybody, please, look at my function file?
I'm sorry for the long post, I can delete it later.
Something does not work, and I'm even not sure where to look for the error message :)
[General Information] Function Name = test Brief Description = Function Source = fgroup.NewFunction Number Of Parameters = 4 Function Type = User-Defined Function Form = Expression Path = Number Of Independent Variables = 1 Number Of Dependent Variables = 1 FunctionPrev = NewFunction
[Fitting Parameters] Names = A,B,C,D Initial Values = 100.000000(V),500.000000(V),500.000000(V),100.000000(V) Meanings = ?,?,?,? Lower Bounds = --(X, Off),--(X, Off),--(X, Off),--(X, Off) Upper Bounds = --(X, Off),--(X, Off),--(X, Off),--(X, Off) Naming Method = User-Defined Number Of Significant Digits = -1,-1,-1,-1
[Independent Variables] x =
[Dependent Variables] y =
[Formula] B*x + A+D* sin(C*x)
[Initializations]
[After Fitting]
[Controls] General Linear Constraints = 0 Initialization Scripts = 0 Scripts After Fitting = 0 Number Of Duplicates = N/A Duplicate Offset = N/A Duplicate Unit = N/A Generate Curves After Fitting = 1 Curve Point Spacing = Uniform on X-Axis Scale Generate Peaks After Fitting = 1 Generate Peaks During Fitting = 1 Generate Peaks with Baseline = 1 Paste Parameters to Plot After Fitting = 1 Paste Parameters to Notes Window After Fitting = 1 Generate Residuals After Fitting = 0 Keep Parameters = 0 Compile On Param Change Script = 1 Enable Parameters Initialization = 1
[Compile Function] Compile = 0 Compile Parameters Initialization = 1. OnParamChangeScriptsEnabled = 0.
[Parameters Initialization] A=100; B=500; C=500; D=100;
[Origin C Function Header] #pragma warning(error : 15618) #include <origin.h>
// Add your special include files here. // For example, if you want to fit with functions from the NAG library, // add the header file for the NAG functions here.
// Add code here for other Origin C functions that you want to define in this file, // and access in your fitting function.
// You can access C functions defined in other files, if those files are loaded and compiled // in your workspace, and the functions have been prototyped in a header file that you have // included above.
// You can access NLSF object methods and properties directly in your function code.
// You should follow C-language syntax in defining your function. // For instance, if your parameter name is P1, you cannot use p1 in your function code. // When using fractions, remember that integer division such as 1/2 is equal to 0, and not 0.5 // Use 0.5 or 1/2.0 to get the correct value.
// For more information and examples, please refer to the "User-Defined Fitting Function" // section of the Origin Help file.
[Origin C Parameter Initialization Header] #include <origin.h>
// Add your special include files here. // For example, if you want to use functions from the NAG library, // add the header file for the NAG functions here.
// Add code here for other Origin C functions that you want to define in this file, // and access in your parameter initialization.
// You can access C functions defined in other files, if those files are loaded and compiled // in your workspace, and the functions have been prototyped in a header file that you have // included above.
// You can access NLSF object methods and properties directly in your function code. // You should follow C-language syntax in defining your function. // For instance, if your parameter name is P1, you cannot use p1 in your function code. // When using fractions, remember that integer division such as 1/2 is equal to 0, and not 0.5 // Use 0.5 or 1/2.0 to get the correct value.
// For more information and examples, please refer to the "User-Defined Fitting Function" // section of the Origin Help file.
[Constraints]
|
|
|
larry_lan
China
Posts |
Posted - 04/20/2010 : 06:05:02 AM
|
Please try this tutorial first. For any more questions, please start a new thread.
Thanks Larry |
|
|
sachamaillot
France
1 Posts |
Posted - 03/13/2012 : 12:11:59 PM
|
Hi.
As it is a topic I found still today on google when typing "origin Unable to compile user defined function", it might be worth to mention what I found to solve the same problem. I'm using Origin 7.5, I had to make my own function. When I had to perform a fit it gave me the same error message (unable to compile). Reading through doc, I found that I had to uncheck "Use Origin C" in the "Edit Function" panel and then select "Y-script" out of "Expression", "Y-script", "Equations". I don't know if it will be of any help for the first person, hope it will for the next who will be reading the thread.
Kind regards
|
|
|
|
Topic |
|
|
|