Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Area Integral for Data Curve
Date: Fri, 16 Dec 2011 17:19:08 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 21
Message-ID: <jcfuic$7gj$1@newscl01ah.mathworks.com>
References: <jcfqog$nuc$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-03-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1324055948 7699 172.30.248.48 (16 Dec 2011 17:19:08 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 16 Dec 2011 17:19:08 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:752555

"maria " <rosariamaria@hotmail.it> wrote in message <jcfqog$nuc$1@newscl01ah.mathworks.com>...
> In particular I would like to know the area of the regions of this curve that is up and down a line that i create connecting two points respectively [x(1,1) y(1,1)] and [x(1:end) y(1:end)].
> 
> My data are non linear so when i plot this line and the datas there is part of the Y vs X curve that is on one side of this two-points line and part on the other side.
> I would like to calculate those two areas that are separated by the line i created.
> How can I do if i don't know the form of my datas?
> is there a way to calculate such a integral?
- - - - - - -
  Do you wish the areas below the line to count as negative quantities and those above as positive?  In that case the answer is easy.  Just use 'trapz' in which the "Y" is defined in terms of your 'y' as:

 Y = y - ( y(1) + (x-x(1))*(y(end)-y(1))/(x(end)-x(1)) );

namely the difference between your curve height and the height of the straight-line segment.  In some places Y may be positive and in some, negative.

  On the other hand, if you want both kinds of areas to count as positive quantities, the problem is harder.  What you need is the integral of the absolute value of the above Y.  Or perhaps you want to find each separate area.

  To use 'trapz' for either of these purposes it would be necessary to determine all the crossing points (if any) between your curve and the straight line, and to separately integrate the absolute value of the above function Y over each of the intervals so defined.

  You need to tell us which kind of integral you want to find.

Roger Stafford