"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 twopoints 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) + (xx(1))*(y(end)y(1))/(x(end)x(1)) );
namely the difference between your curve height and the height of the straightline 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
