Author |
Topic  |
|
SKANTHA5
Germany
6 Posts |
Posted - 03/23/2011 : 09:24:12 AM
|
Origin Ver. and Service Release (Select Help-->About Origin): Operating System: Windows Vista I have the following equation.

x in the above equation is defined as x= (Uo*Ms*PI*(Dmag)^3)/(6*(1.38*10^-23)*300); //I used it in the code. Fit parameters: Nt,D,Uo*H,w. Independent variable: Dmag, Dependent variable: mt(h,t) or simply Mt.
As, shown in the above expression I am trying to fit my data using this expression. So, I used fitting function organizer for coding. I wrote code for the user defined function which I want to use for fitting. I read all the help docs related to that topic. Noting seems to work, it gives compilation errors. The code I wrote with the help of help docs is given belp. -------- Here is my program----------- #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. // I included this for using NAG functions here. #include <oc_nag8.h> //#include <nag.h> //#include <nags.h> struct user { double b, c, d, z; //a=N_t, b=D, c=W_mag, d=uH; }; // Function supplied by user, return the value of the integrand at a given D_mag. static double NAG_CALL f_callback(double D_mag, Nag_User *comm) // { struct user *sp=(struct user *)(comm->p); double b, c, d; //a = sp->a; b = sp->b; c = sp->c; d = sp->d; //z = sp->z; //z = ((d*PI*0.092*(D_mag^3))/(6*(4.1420*10^-021))); //double cothz = double cosh(z)/double sinh(z); return ((0.0153*PI*(D_mag*D_mag*D_mag))*(((cosh((d*PI*0.092*(D_mag^3))/(6*(4.1420*10^-021))))/(sinh((d*PI*0.092*(D_mag^3))/(6*(4.1420*10^-021)))))-((6*(4.1420*10^-021))/(d*PI*0.092*(D_mag^3))))*((1/c*sqrt(2*PI)*b)*exp(-(1/2)*((log(b/D_mag))/c)*((log(b/D_mag))/c)))); //((0.0153*PI*(D_mag*D_mag*D_mag))*((cosh((d*PI*0.092*(D_mag^3))/(6*(4.1420*10^-021))))/()-((6*(4.1420*10^-021))/(d*PI*0.092*(D_mag^3)))*((1/c*sqrt(2*PI)*b)*exp(-(1/2)*((log(b/D_mag))/c)*((log(b/D_mag))/c)))); // expression you want to enter }
//---------------------------------------------------------- // void _nlsfmag_moment( // Fit Parameter(s): double N_t, double D, double W_mag, double uH, // Independent Variable(s): double D_mag, // Dependent Variable(s): double& M_t) { // Beginning of editable part // Through the absolute accuracy epsabs, relative accuracy epsrel and max_num_subint you can // control the precision of the integration you need // if epsrel is set negative, the absolute accuracy will be used. // Similarly, you can control only relative accuracy by set the epsabs negative double epsabs = 0.0, epsrel = 0.0001; // The max number of sub-intervals needed to evaluate the function in the integral // The more diffcult the integrand the larger max_num_subint should be // For most problems 200 to 500 is adequate and recommmended Integer max_num_subint = 200; // Result keeps the approximate integral value returned by the algorithm // abserr is an estimate of the error which should be an upper bound for the |I - result| // where I is the integral value double result, abserr; // The structure of type Nag_QuadProgress, // it contains pointers allocated memory internally with max_num_subint elements Nag_QuadProgress qp; // The NAG error parameter (structure) static NagError fail; // Parameters passed to integrand by Nag_User communication struct Nag_User comm; struct user s; //s.a = N_t; s.b = D; s.c = W_mag; s.d = uH; comm.p = (Pointer)&s; // Perform integration // There are 3 kinds of infinite boundary types you can use in Nag infinite integrator // Nag_LowerSemiInfinite, Nag_UpperSemiInfinite, Nag_Infinite d01smc(f_callback, D_mag, Nag_UpperSemiInfinite, epsabs, epsrel, max_num_subint, &result, &abserr, &qp, &comm, &fail); // you may want to exam the error by printing out error message, just uncomment the following lines // if (fail.code != NE_NOERROR) // printf("%s\n", fail.message); // For the error other than the following three errors which are due to bad input parameters // or allocation failure NE_INT_ARG_LT NE_BAD_PARAM NE_ALLOC_FAIL // You will need to free the memory allocation before calling the integration routine again to avoid memory leakage if (fail.code != NE_INT_ARG_LT && fail.code != NE_BAD_PARAM && fail.code != NE_ALLOC_FAIL) { NAG_FREE(qp.sub_int_beg_pts); NAG_FREE(qp.sub_int_end_pts); NAG_FREE(qp.sub_int_result); NAG_FREE(qp.sub_int_error); } // Calculating the final value. M_t = N_t * result; // End of editable part }
APK |
|
SKANTHA5
Germany
6 Posts |
Posted - 03/23/2011 : 10:06:01 AM
|
Can anyone please give me suggestions how to code this equation properly...So, that I can carry on with the fitting.
APK |
 |
|
easwar
USA
1965 Posts |
Posted - 03/23/2011 : 10:26:56 AM
|
Hi APK,
For advanced issues such as this, please contact tech support directly. You can find link on top of the forum page "Send File to Tech Support". Please then send relevant data, your fitting function and any other files necessary.
Easwar OriginLab
|
 |
|
SKANTHA5
Germany
6 Posts |
Posted - 03/23/2011 : 11:00:47 AM
|
Thank you so much for the reply, I am working on this problem for last month and half. But, my question is, can Origin 8.5, powerful enough to solve this complex integral curve fitting functions.
APK |
 |
|
easwar
USA
1965 Posts |
Posted - 03/23/2011 : 11:29:35 AM
|
Hi APK,
I just now tried defining your function and the first compile error I got was on this line:
return ((0.0153*PI*(D_mag*D_mag*D_mag))*(((cosh((d*PI*0.092*(D_mag^3))/(6*(4.1420*10^-021))))/(sinh((d*PI*0.092*(D_mag^3))/(6*(4.1420*10^-021)))))-((6*(4.1420*10^-021))/(d*PI*0.092*(D_mag^3))))*((1/c*sqrt(2*PI)*b)*exp(-(1/2)*((log(b/D_mag))/c)*((log(b/D_mag))/c))));
There is a limit on number of characters per line, so that is perhaps why this line is not compiling. Try breaking this up by computing the expression as a few separate terms and then combine the terms using another line.
Then if you still run into issues, send your FDF and data to tech. Hard to work this way using code posted on forum, not very efficient.
Thanks,
Easwar OriginLab |
 |
|
SKANTHA5
Germany
6 Posts |
Posted - 03/23/2011 : 11:38:38 AM
|
I totally agree Mr. Easwar. I can thank you enough for trying. Your suggestion sounds good, splitting into individual terms. Got to try with that. Thanks again. If I get this result I will post it.
APK |
 |
|
easwar
USA
1965 Posts |
Posted - 03/23/2011 : 11:44:15 AM
|
Hi APK,
We noticed that you have 10^-21 in multiple places in that line.....change that to 1e-21 and it works fine.
When using ^ if the power is negative, need to put that in () such as 10^(-21) or change to 1e-21 in your case. We will look into this issue.
When I make this change, your function compiles fine, so you can then try and see if it fits.
Easwar OriginLab |
 |
|
SKANTHA5
Germany
6 Posts |
Posted - 03/23/2011 : 11:53:43 AM
|
I am trying with you suggestions Mr. Easwar. Hoping for the best.
APK |
 |
|
SKANTHA5
Germany
6 Posts |
Posted - 03/23/2011 : 11:57:53 AM
|
The code compiled perfect without errors this time. But have to check for fitting the data. I mean incredible support Mr. Easwar. I don't know what to say.
APK |
 |
|
|
Topic  |
|
|
|