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 with integral in Origin C
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

jazgara@un1

Poland
6 Posts

Posted - 01/31/2003 :  06:12:48 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi,
I would like to create fuction with integral in origin C, and then call the fuction from NLSF, but I have problem with "return" statement. I don't know how to write correctly the last line in my script.
My fuction: I=(A/(pi*w))*integral(W(b)/(1+(xval-alfa^(4/3)*b)^2)db)
My script:
void Aga(double x, double lc, double d, double w, double alfa, double A)
{
Dataset xval ("Data1_C");
xval=(x-lc-d)/w;
Dataset b ("Data1_b"); //it is given
Dataset alfab ("Data1_D");
alfab=(alfa^(4/3))*b^2;
for (int ii = 1; ii <= 32; ii++)
{
Dataset D ("Data1_E");
D=1/(1+(xval[ii]-alfab)^2);
Dataset F ("Data1_F");
Dataset Wb ("Data1_Wb"); //it is given
F = Wb*D;
Curve cvMyCurve("Data1_b", "Data1_F");
IntegrationResult irMyResults;
Curve_integrate(&cvMyCurve, &irMyResults);
Dataset G ("Data1_G");
G[ii]=irMyResults.Area;
}
double C;
C=A/(pi*w);
Dataset H ("Data1_H");
Dataset G ("Data1_G");
H=C*G;
return H;
}



Can you help me?
Aga

Edited by - jazgara@un1 on 01/31/2003 06:15:54 AM

Edited by - jazgara@un1 on 01/31/2003 06:25:40 AM

Edited by - jazgara@un1 on 02/03/2003 05:32:19 AM

hajo_old

Germany
141 Posts

Posted - 01/31/2003 :  07:03:25 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello, - jazgara@un1

what type is H ?

Your function definition starts with:


void Aga(double x, double lc, double d, double w, double alfa, double A)
{
.....
return H;
}


void tells the compiler, that there is no variable given back to the calling routine.

the function call should be:
e.g. H is type float:


float Aga(double x, double lc, double d, double w, double alfa, double A)
{
.....
return H;
}


Hope this helps


-- --
Dipl.-Ing. Hans-Joerg Koch
Siemens VDO, Regensburg

SVDO_Origin1
Go to Top of Page

yuivanov

USA
11 Posts

Posted - 01/31/2003 :  10:46:53 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Tadeusz.
There are multiple problems with your function definition.
1. As it is already mentioned if you declare function as "void" it is not supposed to return a value. If you want your function to return Dataset you need to change declaration to
Dataset Aga(double x, double lc, double d, double w, double alfa, double A)
2. OriginC obeys most rules of C language so you need to declare variable before it can be used. In some cases you do declare in some not.
Also I noticed that your "for" loop is from 1 to <= 32; Origin C indices are zero based. So most probably you need to change it to be:
for( int ii = 0; ii < 32; ii++ )
Unless you need to loop from the 2nd to 33rd line of dataset.

3. It appears to me that in some cases you use Dataset just for calculation purposes. Dataset is representation of internal Origin object while vector does not have such ties. In other words if you need an array to hold you intermediary results and do not need those results to be placed into the worksheet declare

vector<double> vData;
vData.SetSize(32);

After that you may work with it just like you do with dataset of size 32. Your Dataset D seems to be such an intermediary result;
Also if result of your function is going to be used in further calculation and you do not need it to be inside worksheet then function should return vector<double> and your return variable "H" be of vector type.

Calling function declared somewhere else from NLSF is a little tricky. This will be simplified in the next service release.

Let say your function is in the file
MyIntegration.c
Create new file
MyIntegration.h
and add your function declaration there
vector<double> Aga(double x, double lc, double d, double w, double alfa, double A);
Open file named NLSF.fit (this can be found in "OriginC\Nlsf\" folder in your installation directory)
and add line
#include "MyIntegration.h"
To be on safe side you may provide whole path to ensure that comiler finds this file. So it will be like:
#include "D:\MyOriginCalculations\MyIntegration.h"
this will allow you to call your function from inside NLSF fitting function.
Before using NLSF add "MyIntegration.c" file into workspace and compile.

Thanks
Yuri

Edited by - yuivanov on 01/31/2003 10:50:03 AM
Go to Top of Page

jazgara@un1

Poland
6 Posts

Posted - 02/03/2003 :  02:29:33 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you very much,
It really helps, but I still have troubles with my "for" loop.
Aga

Edited by - jazgara@un1 on 02/03/2003 05:31:14 AM
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