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
 LabTalk Forum
 Perform simulation
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

kemcelroy

USA
13 Posts

Posted - 01/13/2005 :  4:01:03 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin): 7SR4
Operating System: Windows XP

I often need to plot simulated curves with my data, so I want to write code to automate this. I know how to fit a curve with the NLSF fitter using LabTalk in OriginC code, but I can't find "simulate" method in the help files.

For right now, I am going to try to just open the NLSF Simulate dialog box and then the user (me) will have to click on the simulate curves button. Hopefully I can get the parameters and start and end values to appear automatically so I can save a little time, but I'd really like to know if I can do this better. Any suggestions would be wonderful.

kemcelroy

USA
13 Posts

Posted - 01/13/2005 :  10:54:53 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I'm having trouble accessing some of the parameters in the Simulation dialog box. In the screen shot below, you see the dialog box for my function.

This function has 3 parameters and 2 independent variables. I can use LabTalk commands in Origin C to update the 3 parameters (upper right) and the beginning and end for one variable (named "S1", bottom). I can not change the beginning and end for the other variable, or set the number of points for the first variable. The commands that I've tried are:
NLSF.p1 = 10;
NLSF.p2 = 6;
NLSF.p3 = 412;
NLSF.xbegin = 0; //this works for the first independent variable
NLSF.xend = 150; //this works for the first independent variable
NLSF.xPoints = 300; //this does not work...it stays as default 51

Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 01/14/2005 :  1:05:56 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You might also try adjusting nlsf.xStep. My guess that its current value is 3 (=150/50). Try this...

nlsf.xStep = 0.5; // should create 1 + 150/0.5 = 301 points
nlsf.xPoint = 301; // this might not even be necessary

...I just tried that and it doesn't work. If you have the NLSF fitter open you can change the number of points like this...

1. Switch to an "Action" other than Simulate (e.g., Fit).
2. Run your script (nlsf.xPoints=300).
3. Switch back to Simulate and you'll find the 300 points.

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 01/14/2005 3:55:42 PM
Go to Top of Page

easwar

USA
1965 Posts

Posted - 01/14/2005 :  4:16:33 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

If all you want is to generate a table of Y values for a given table of X values using an existing NLSF function, you can do that directly in OC using code such as below, without having to use the LabTalk NLSF object.

Here, the Gauss function is being used and so the OC function name is nlfGauss and nlfxGauss respectively. For your FDF, look at what the function name is (typically function name, which is a property inside the FDF, is same as the FDF file name), and then you can make change to code so that you write it as nlfYourFunctionName or nlfxYourFunctionName.

Easwar
OriginLab


void simulate_func()
{
// Create new wks and declare x,y datasets
Worksheet wks;
wks.Create();
Dataset dsX(wks, 0);
Dataset dsY(wks, 1);
if( !dsX || !dsY ) return;

// Fill x dataset with desired x values
dsX.Data(1, 10, 0.1);
// Set size of y dataset to be same as x dataset
int iSize = dsX.GetSize();
dsY.SetSize(iSize);

// Set up an array of parameters for the NLSF function
double dPar[4];
dPar[0] = 10; // y-offset
dPar[1] = 5.5; // xc
dPar[2] = 3; // w
dPar[3] = 100; // A
// Fill Y with Gauss function using x values from dsX
for(int ii = 0; ii < iSize; ii++)
dsY[ii] = nlfGauss(dsX[ii], dPar, 4);

// Or can directly pass parameters such as:
for(ii = 0; ii < iSize; ii++)
dsY[ii] = nlfxGauss(dsX[ii], 5.0, 6.5, 3.0, 100.0);
}


Go to Top of Page

kemcelroy

USA
13 Posts

Posted - 01/14/2005 :  8:48:43 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Mike's solution worked (Thanks, Mike!). I realized that I only want to use one value for the second independent variable for this simulation, so I made it a parameter, which I can now assign.

I open the simulate dialog box, then open a message box so I can click "Create Curve" without the script continuing without me. Then I need to click "OK" on the message box. It seems like there must be a way to access the "Create Curve" method, but for right now I have a semi-automated process.

The idea from Easwar sounds like it would work if I weren't using a User-defined function. If anyone knows how to use an nlf type of command with a user-defined FDF, let me know since this would certainly be the best solution.
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 01/15/2005 :  01:58:22 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
It seems like there must be a way to access the "Create Curve" method
Use nlsf.makecurve() or nlsf.fit().

Mike Buess
Origin WebRing Member
Go to Top of Page

kemcelroy

USA
13 Posts

Posted - 01/15/2005 :  5:16:28 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I can't get nlsf.makecurve() or nlsf.fit() to make a simulated curve. I'm not fitting a dataset, and my understanding of how these functions work is that you need to fit a dataset first, then you can make a curve from the fitted data.
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 01/15/2005 :  7:36:40 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
I'm not fitting a dataset,
I didn't catch that part before. And you can't use Easwar's code because you defined your function yourself. (I really should read more carefully.) This LabTalk solution will work. It uses the fit() function to generate a Y dataset from a given X dataset using your NLSF function and the parameters you gave earlier. Just substitute the real function name for MyFunc. I tried it with one of my own fitting functions and it works fine.

win -t D;
col(A)=data(0,150,0.5);
nlsf.func$=MyFunc;
nlsf.p1=10;
nlsf.p2=6;
nlsf.p3=412;
col(B)=fit(col(A));

...Note that this can also be done with nlsf.makeCurve(), which also plots the curve.

win -t D;
col(A)=data(0,150,0.5);
nlsf.func$=MyFunc;
nlsf.p1=10;
nlsf.p2=6;
nlsf.p3=412;
nlsf.xmode=2;
nlsf.funcx$=%H_A;
nlsf.funcCol$=%H_B;
nlsf.makeCurve(func);
lay -a; // rescale to show all data

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 01/15/2005 8:55:35 PM

Edited by - Mike Buess on 01/15/2005 9:00:37 PM

Edited by - Mike Buess on 01/15/2005 11:01:25 PM

Edited by - Mike Buess on 01/15/2005 11:16:01 PM
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