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
 Origin Forum
 find slope near y=0
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

crisshartzell

USA
3 Posts

Posted - 04/21/2004 :  3:24:24 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
I have a large series of non-linear curves. I would like to automatically determine the x-intercept and calculate the slope of the line in the vicinity of the x-intercept (in this region the line is approximately linear). I would appreciate any suggestions on how to acomplish this. Thanks.
Criss

Mike

USA
357 Posts

Posted - 04/22/2004 :  09:39:26 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Criss, I don't think that this is going to be terribly difficult for you, but it's tough to say what your best course of action would be without more specifics. I assume that when you say you have a "large series of non-linear curves," you have used Origin's Advanced Fitting Tool (NLSF) to find "best-fit" equations for a series of data sets. Were all curves fit to the same model? When you say that you would like to "calculate the slope of the line in the vicinity of the x-intercept," you'll have to come up with some hard numbers, of course -- some upper and lower limits on x or y values.

Without knowing more about your project, it is possible that you could do this entirely within the NLSF interface, by making use of an "After Fitting" script that runs upon completion of the curve fitting session. But this, of course, will require some scripting on your part. If you can furnish some more details about how you expect to get your data into Origin, how you plan to fit curves to those data, and how you plan to determine/define the region in which you intend to measure the slope, someone may be able to help you with some of the scripting details.

Mike
OriginLab
Go to Top of Page

easwar

USA
1964 Posts

Posted - 04/22/2004 :  1:32:29 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Criss,

If I understand you correctly, you have raw data that is mostly nonlinear, but is linear around the y=0 axis and so you want to fit just that section of the data to a straight line and get the slope and intercept.

If this is what you want, try the LabTalk script code pasted below. First graph the data, keep the graph window active, then go to the script window, copy and paste this code, highlight all the lines of code and hit enter.

You can create a macro out of the code, or an OGS file - look up the help files on how to do that.

Just another note on LabTalk. If you had wanted to fit a line to just the beginning or end portion of a dataset, you can do that with LabTalk with the "lr -b" and "lr -e" commands which automatically look for a linear segment at the beginning or end. In your case the linear part could be in the middle of the data and so this needs to be coded separately such as below.

Easwar
OriginLab




// First check if data crosses y=0
sum(%c);
if( sum.min*sum.max >= 0 )
{
type "Data does not cross y=0!";
return;
};

// Now find the x value that corresponds to y=0 using interpolation
xaty0 = table( %c, xof(%c), 0 );

// Now find the point in the dataset that is closest to this x value
ixaty0 = xindex( xaty0, %c );

// Find the size of the dataset
inumpts = sum.n;

// Set the lower and upper bounds to be +/- 10% of dataset size around the y=0 point;
// You can change the 10% to some other suitable value, or use some other method to set this range;
ixlow = nint( ixaty0 - inumpts * 0.1 );
ixhigh = nint( ixaty0 + inumpts * 0.1 );

// If the computed limits are outside the dataset, reset to dataset limits
if( ixlow < 1 ) ixlow = 1;
if( ixhigh > inumpts ) ixhigh = inumpts;

// Now set data markers to correspond to the upper and lower bounds computed above
mks1 = ixlow;
mks2 = ixhigh;

// Refresh the graph
doc -uw;

// Perform linear regression
lr %c;

// Report intercept and slope values found
type "intercept = $(lr.a)";
type "slope = $(lr.b)";

// Reset the data markers - optional - may want to leave out if you want to see markers
mks1 = -1;
mks2 = -1;
Go to Top of Page

crisshartzell

USA
3 Posts

Posted - 04/22/2004 :  4:50:59 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Easwar-
Thank you for your help!
The script that you wrote does exactly what I wanted to do!
I guess I need to learn LabTalk, it looks pretty cool!
Criss


quote:

Hi Criss,

If I understand you correctly, you have raw data that is mostly nonlinear, but is linear around the y=0 axis and so you want to fit just that section of the data to a straight line and get the slope and intercept.

If this is what you want, try the LabTalk script code pasted below. First graph the data, keep the graph window active, then go to the script window, copy and paste this code, highlight all the lines of code and hit enter.

You can create a macro out of the code, or an OGS file - look up the help files on how to do that.

Just another note on LabTalk. If you had wanted to fit a line to just the beginning or end portion of a dataset, you can do that with LabTalk with the "lr -b" and "lr -e" commands which automatically look for a linear segment at the beginning or end. In your case the linear part could be in the middle of the data and so this needs to be coded separately such as below.

Easwar
OriginLab




// First check if data crosses y=0
sum(%c);
if( sum.min*sum.max >= 0 )
{
type "Data does not cross y=0!";
return;
};

// Now find the x value that corresponds to y=0 using interpolation
xaty0 = table( %c, xof(%c), 0 );

// Now find the point in the dataset that is closest to this x value
ixaty0 = xindex( xaty0, %c );

// Find the size of the dataset
inumpts = sum.n;

// Set the lower and upper bounds to be +/- 10% of dataset size around the y=0 point;
// You can change the 10% to some other suitable value, or use some other method to set this range;
ixlow = nint( ixaty0 - inumpts * 0.1 );
ixhigh = nint( ixaty0 + inumpts * 0.1 );

// If the computed limits are outside the dataset, reset to dataset limits
if( ixlow < 1 ) ixlow = 1;
if( ixhigh > inumpts ) ixhigh = inumpts;

// Now set data markers to correspond to the upper and lower bounds computed above
mks1 = ixlow;
mks2 = ixhigh;

// Refresh the graph
doc -uw;

// Perform linear regression
lr %c;

// Report intercept and slope values found
type "intercept = $(lr.a)";
type "slope = $(lr.b)";

// Reset the data markers - optional - may want to leave out if you want to see markers
mks1 = -1;
mks2 = -1;


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