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 and Interpolation
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

junsung

Germany
Posts

Posted - 11/14/2006 :  12:01:54 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin): 7.5853
Operating System: Window XP (SP2)

Hi, all
I tried to do some fitting using interpolation, but it seems not working well. My fitting function cannot be written in an equation form, so I have only a data set, F[x]. Say, Fitfunction_A = x and Fitfuction_B=F[x].
The fitting equation is "y = g0+F[t0/x]", and I tried with the following code, but I always got an error message. Could you be kind to tell me why this is not working? Any comments or suggestions will be very helpful for me.




In the NLSF. "Use Origin C" is on.

--------------
static double g0store, t0store;
Dataset dsX("Data1_x");//Dataset for fitting
Dataset dsscaleX("Data1_scaleX");//to get "t0/x"
Dataset dsExpv;
Curve fitFunction("fitFunction_A", "fitFunction_B");//Dataset for F[x]
int nSize= dsX.GetUpperBound();
if(g0!=g0store || t0!=t0store) {
dsscaleX = t0/ dsX;
for(int ii=0;ii<nSize; ii++) {
dsExpv[ii] = Curve_yfromX (&fitFunction, dsscaleX[ii]) ;
};
g0store=g0; t0store=t0;
};
y=g0+Data_table(x, &dsExpv, &dsX);

zachary_origin

China
Posts

Posted - 11/14/2006 :  9:36:25 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
From the code, what I can find is that you defined a dataset "dsExpv" but did not attach it to an existing origin object. This is not valid in Origin C. So you need add a column and attach the column to dsExpv. The code can be changed as following. I have simulated it with F(x) = x^2, it works fine.


static double g0store, t0store;
Dataset dsX("Data1_x");//Dataset for fitting
Dataset dsscaleX("Data1_scaleX");//to get "t0/x"
Dataset dsExpv("Data1_Expv"); //Manually add a column named Expv in Data1
Curve fitFunction("fitFunction_A", "fitFunction_B");//Dataset for F[x]
int nSize= dsX.GetUpperBound();
if(g0!=g0store || t0!=t0store)
{
dsscaleX = t0/ dsX;
dsExpv.SetSize(nSize); //It would be better to set the size of the dataset before using it to avoid some runtime error
for(int ii=0;ii<nSize; ii++)
{
dsExpv[ii] = Curve_yfromX (&fitFunction, dsscaleX[ii]) ;
}
g0store=g0;
t0store=t0;
}
y=g0+Data_table(x, &dsExpv, &dsX);

////End of function



Zachary
OriginLab Technical Services.

Edited by - zachary_origin on 11/14/2006 9:40:02 PM
Go to Top of Page

junsung

Germany
Posts

Posted - 11/17/2006 :  6:32:49 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Dear Zachary

Thank you so much!! I took your advice, and it works perfect!
If you don't mind, I'd like ask one more question about it.
Actually, my fitting function contains also the exponential function with two more parameters like "y=g0+F[t0/x]+g1*Exp[t1/x]".
I changed the last line in the program such as
y=g0+Data_table(x, &dsExpv, &dsX)+g1*Exp(t1/x);
but, it seems that Exp(x) function is not defined.
Could you be kind to tell me why it is so, and how to fix it?

best,

Jun Sung
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 11/17/2006 :  9:44:58 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Jun Sung,

Origin C is case sensitive. Use exp(t1/x) instead of Exp(t1/x).

Mike Buess
Origin WebRing Member
Go to Top of Page

junsung

Germany
Posts

Posted - 11/23/2006 :  5:03:50 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Dear Zachary and Mike

Thank you so much! It works very well now.
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