Author |
Topic  |
|
verma
Japan
1 Posts |
Posted - 02/27/2003 : 01:02:42 AM
|
Hello all, I have written the code for my function in OriginC and when I call my function from Labtalk I get the error message : COMMAND ERROR!! Can any one help me how to overcome this. I could compile the code wihtout any error message. My code goes like this
#define R 8.315 int i, d1plusd2, d1intod2, d1d1, d2d2; double rbyt2, ed1d2byt, ed1, ed2, dr, nr, nr1, nr2, nr3;
double thamizh (string wksName, int DELTA1, int DELTA2) {
Worksheet wks(wksName); int rows = wks.GetNumRows(); Dataset dd1(wksName, 0); Dataset dd2(wksName, 1); d1plusd2 = DELTA1 + DELTA2; d1intod2 = DELTA1 * DELTA2; d1d1 = DELTA1 * DELTA1; d2d2 = DELTA2 * DELTA2;
for (i = 0; i <= rows; i++) { rbyt2 = (R / (dd1[i] * dd1[i])); ed1d2byt = exp(d1plusd2/dd1[i]); ed1 = exp(DELTA1/dd1[i]); ed2 = exp(DELTA2/dd1[i]); dr = (ed1 + ed2 + ed1d2byt) * (ed1 + ed2 + ed1d2byt); nr1 = -2 * d1intod2; nr2 = d2d2 * (1 + ed1); nr3 = d1d1 * (1 + ed2); nr = rbyt2 * ed1d2byt * (nr1 + nr2 + nr3);
return nr/dr;
} }
void thamizhfit (Worksheet wksData) { Dataset dsX(wksData, 0); Dataset dsY(wksData, 1); Curve crvData(wksData,0,1); GraphPage grphData; string strGrphTemplate = "scatter.otp"; int nOptionG = CREATE_VISIBLE_SAME; grphData.Create(strGrphTemplate, nOptionG); GraphLayer grphLayer= grphData.Layers(); int nPlot = grphLayer.AddPlot(crvData, IDM_PLOT_SCATTER); grphLayer.Rescale(); //Perform nonlinear Fit to the Plotted Data using NLSF = LabTalk.NLSF; NLSF.PasteToPlot = 1; NLSF.Func$ = "thamizh"; //user Defined Function NLSF.FitWksName$ = "wksData"; NLSF.n$ = "DELTA1", "DELTA2"; //names of Input Paramters NLSF.n1 = 1; NLSF.n2 = 2; NLSF.p1 = 30; //Initial Guess for the Paramter 1 NLSF.p2 = 200; //Initial Guess for the Parameter 2 NLSF.fit(50); //Number of fitting iterations }
|
|
Laurie
USA
404 Posts |
Posted - 02/27/2003 : 09:41:17 AM
|
Because you are running your 'thamizhfit' function from the Script Window, you need to pass it a string. LabTalk doesn't know about the Worksheet class. If you were calling this function from another Origin C function then it would be ok, but to call it from LabTalk the argument should be similar to the 'thamizh' function which takes a string and then within the function declares a worksheet object.
The other problem that I notice is that you've used ' NLSF.Func$ = "thamizh";'. In order for this to work, you need to have defined a new function from within the NLSF, where the name of the function is thamizh, and saved it as an FDF file.
Make sure that you have Origin 7 SR3. Check Help:Check for Updates to make sure that you have the latest update. Open the Advanced fitter by selecting Analysis:Non-linear Curve Fit:Advanced Fitting Tool. Select Function:New and define your function in Origin C by clicking the Edit in CodeBuilder button.
Any questions, let me know.
OriginLab Technical Support |
 |
|
|
Topic  |
|
|
|