The Origin Forum
File Exchange
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
 x-intercept and integrate
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

robuiuc

USA
4 Posts

Posted - 06/03/2012 :  9:04:43 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): 8.6.0 64bit, b70
Operating System: win7

I have a relatively simple problem, and I haven't been able to find (what I'm assuming should be) concise code to solve it.

I have a sinusoidal data set and I'm trying to find the first x-intercept, and then integrate the data from 0 to that value. The code I've attempted is below. I tried to specify a certain data range, but I always get the 3rd (last) x-intercept. Also, the integrate command (when it works), integrates the entire data set. What modifications do I need to make to the code? If it simplifies things, the x-intercept for all data sets is always in between x = 0.5-1. Thanks much.

range r1 = col(1)[0:2250]; //attempting to limit data to 1st x intercept
range r2 = col(2)[0:2250];
r2(0);
r1(0, r2)=;
s1 = r1(0, r2); //attempting to set s1 = x intercept
int ix1=xindex(0,%c);
int ix2=xindex(s1,%c); //integrate from 0-s1?
range rr=(%c)[$(ix1): $(ix2)];
integ1 rr;
integ1.=;

Kathy_Wang

China
127 Posts

Posted - 06/04/2012 :  05:51:17 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi
The problem with your script is mostly that you used invalid range notation, there are three parts in the script you will need to modify for this reason.

1. When you define range r1 and r2, the row index starts from 1 rather than 0;

2. When you define integrals ix1 and ix2, instead of "%c", you should use "r2" as the range, also it is recommended that you introduce the control variable 2 to find values both from left and right, otherwise the script won稚 work when you starting value is not 0;

3. When you define range rr for integration, instead of using
(%c)[$(ix1): $(ix2)];
use
1[$(ix1)]:2[$(ix2)];
here I assumed your XY range is column 1 and 2, if not, you will need to modify the script accordingly.

In addition, an equal mark is missing after "r2(0)".

Here I helped to modify the script as following, which you might try:
range r1 = col(1)[1:2250]; //attempting to limit data to 1st x intercept
range r2 = col(2)[1:2250];
r2(0)=;
r1(0, r2)=;
s1 = r1(0, r2);
int ix1=xindex(0,r2,2);
int ix2=xindex(s1,r2,2); //integrate from 0-s1
range rr=1[$(ix1)]:2[$(ix2)];
integ1 rr;
integ1.=;


Hope this information helps!

Kathy
Originlab
Go to Top of Page

robuiuc

USA
4 Posts

Posted - 06/04/2012 :  08:01:18 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you very much for your quick response. This is a little closer, but I still have two issues:
1. The first two lines of the code do not appear to be working; the range is not restricted to the specified range (first 2250 rows) and it is still finding the last (third) x-intercept.

2. The integration is indeed calculating from the 'correct' data range, but it is not using the right x-values. For my data, x=0 corresponds to row 1000. In the in results log, the integration does not start at 0 (x1 =0), but rather x1 =1000. This is resulting in erroneous integrated areas (vs. when I manually use the GUI). Any suggestions? Thanks.
Go to Top of Page

Laurie

USA
404 Posts

Posted - 06/04/2012 :  10:13:11 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Your script can be simplified to the following 4 lines:

range r1 = 1;
range r2 = 2;
double ix2 = r1(0, r2);
integ1 (r1,r2)[x0:$(ix2)];

Let me know if this works for you.

OriginLab Technical Support
Go to Top of Page

robuiuc

USA
4 Posts

Posted - 06/04/2012 :  10:31:28 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks once again. The integration magnitude is now correct. However, the signal is sinusoidal-- there are three x-intercepts, and this is integrating to the last one. Using the code above, is there a way to either: restrict the input data or somehow specify the first intercept (which always occurs somewhere between x = 0.5-1?
Go to Top of Page

Laurie

USA
404 Posts

Posted - 06/04/2012 :  11:16:14 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
We can simplify it further, to just three lines:

range rxy = (2,1);
double ix2 = rxy(0);
integ1 (r1,r2)[x0:$(ix2)];

It doesn't make sense to me that the second line of code above, for you, is finding the last intercept; it should find the first instance of 0.

Please paste your new code here so I can take alook.

Thank you.

OriginLab Technical Support
Go to Top of Page

robuiuc

USA
4 Posts

Posted - 06/04/2012 :  2:39:30 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I emailed the raw data to Support with reference to this thread. For the time being I am simply using the code provided above. Once I hear back, I will post the response here. I'm not quite sure why restricting the data to the first half cycle does not work.
Go to Top of Page

Laurie

USA
404 Posts

Posted - 06/05/2012 :  5:59:21 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
My apologies....

I think using an xy range for interpolation only works when the X dataset is monotonically increasing or decreasing.

We will email you too...

OriginLab Technical Support
Go to Top of Page

couturier

France
106 Posts

Posted - 06/07/2012 :  3:14:26 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
range r1 = 1;
range r2 = 2;
double ix2 = r1(0, r2);

This is the first time I see a notation such as last line and I can't understand how it works.

Can anyone explain ?
Go to Top of Page

Kathy_Wang

China
127 Posts

Posted - 06/21/2012 :  01:48:38 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by couturier

quote:
range r1 = 1;
range r2 = 2;
double ix2 = r1(0, r2);

This is the first time I see a notation such as last line and I can't understand how it works.

Can anyone explain ?



Hi, the notation r1(0) is used as interpolation through range notation.

Such expression as r1(0,r2) returns to the interpolated X value when the Y value in r2 is equal to 0, and the data set in r1 is used as the X value in this case.


Kathy
Originlab

Edited by - Kathy_Wang on 06/21/2012 04:47:49 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 © 2008 Originlab Corporation Go To Top Of Page
Snitz Forums 2000