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
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Fitting function for drying
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Dr.S

Austria
1 Posts

Posted - 01/07/2019 :  08:24:42 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Dear all,

I am not too familiar with origin C but i tried my best in order to fit some data with a sum function based on cranks laws of diffusion.

I would like to fit the following function to my data:

y = M (1-8/pi²*SUM(1/(2n+1)² * e^(-(2n+1)²*pi²*D*x/h²) )

where the SUM is the Sum operator with n=0 to n =xx (fixed value, tried it with 5).
In order to fit the function, I programmed the following function:

--------------------------------------

#pragma numlittype(push, TRUE)
#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.

//----------------------------------------------------------
//
void _nlsfSUM_Drying(
// Fit Parameter(s):
double D,
// Independent Variable(s):
double x,
// Dependent Variable(s):
double& y)
{
const double M=10410;
const double h=0.0015;
const double p=3.14159;
const double n=5;
// Beginning of editable part


double bb = 0;
for(int ii =1; ii<=n; ii++)
{
bb = (1/(2 * ii + 1)^2) * exp(- (2 * ii +1)^2 * p^2 * D * x / h^2 + bb);
}
y = M *(8/p^2)* bb;
// End of editable part
}

------------------------------------------------

however, fitting does not work and when I try out the function with a fixed value, the result is always 0.
Is there someone who can help me fixing it and make it work?
Thank you very much for your help.

Best regards,
Stefan




Edited by - Dr.S on 01/07/2019 08:26:30 AM

yuki_wu

896 Posts

Posted - 01/07/2019 :  9:40:20 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Stefan,

It seems that you made some mistakes when you wrote the function in the code, for example:

y = M *(8/p^2)* bb;

“1-” is missing.

You need to double check your code.

Regards,
Yuki

OriginLab
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000