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
 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Divide Area under a curve into equal parts

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
sbaruah Posted - 11/07/2005 : 10:27:53 AM
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
2   L A T E S T    R E P L I E S    (Newest First)
sbaruah Posted - 11/09/2005 : 04:33:41 AM
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.
easwar Posted - 11/07/2005 : 1:29:39 PM
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;




The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000