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
 Divide Area under a curve into equal parts
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

sbaruah

Germany
Posts

Posted - 11/07/2005 :  10:27:53 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin): 7
Operating System: Windows xp

Hi,
I am new to programming with Labtalk and will appreciate very much your help.
(1)I have to compute the area under a curve.
(2)Also, I have to divide the area under a curve into 3 parts, each part having equal amount of area.
Can anybody suggest me how to write a labtalk script for that?

Thank you.

Sudarshan Baruah
Greifswald University Germany

Edited by - sbaruah on 11/07/2005 10:41:14 AM

easwar

USA
1965 Posts

Posted - 11/07/2005 :  1:29:39 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Sudarshan,

Plot your data in a grahp, and with the graph active, try the following code. You can copy-paste the code into script window, highlight-select all lines and then hit Enter to execute. You can then save it to OGS file etc - see help files for how to create script file.

Note that this just loops thru x values and computes area to chop up into one-thrids. This works best if there are enough points in the curve. If points are sparse, then area will not get divided into three equal halves etc.

Easwar
OriginLab



// Get size of active curve
limit %c;
nsize = limit.size;

// Find total area under curve
integ %c;
area=integ.area;
farea=area/3;


// Loop thru and find area for 1st one-third part
mks1=1;
for(i=mks1+1; i<=nsize; i++)
{
mks2 = i;
integ %c;
if( integ.area >= farea ) break;
}
xx2 = mks2;
area1=integ.area;

// Loop thru and find area for 2nd one-third part
mks1=xx2;
for(i=mks1+1; i<=nsize; i++)
{
mks2 = i;
integ %c;
if( integ.area >= farea ) break;
}
xx3 = mks2;
area2 = integ.area;

// Find area of 3rd part
mks1 = xx3;
mks2 = nsize;
integ %c;
area3 = integ.area;

// Get x dataset of active curve
%a=xof(%c);

// Report results
type "Total area \t\t\t=" $(area);
type "Area between x=$(%a[1]) to x=$(%a[xx2]) \t=" $(area1);
type "Area between x=$(%a[xx2]) to x=$(%a[xx3]) \t=" $(area2);
type "Area between x=$(%a[xx3]) to x=$(%a[nsize]) \t=" $(area3);

// Reset data markers and refresh page
mks1 = -1;
mks2 = -1;
doc -uw;



Go to Top of Page

sbaruah

Germany
Posts

Posted - 11/09/2005 :  04:33:41 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Easwar,
Thanks for your suggestion. It worked perfectly well. As you said, the uncertainty in the divisions arises from how close the data points are along the X-axis.
Best regards,
Sudarshan.
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