Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Area Integral for Data Curve

Subject: Area Integral for Data Curve

From: maria

Date: 16 Dec, 2011 16:14:09

Message: 1 of 2

Good evening to everyone, i would like to ask some help! I have some data stored in variables Y and X . those datas are not linear and I am interested in integrating the function i have by plotting Y vs X by plot(y,x).
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?



I uploaded here my data files so you can see what i am talking about
http://www.megaupload.com/?d=48AHD2I0

i plot them this way
>> plot(x,y)
>> hold on
>> plot([x(1) x(end)],[y(1) y(end)]);
>>

i need the are enclosed in this plot

thank you so much

 maria

Subject: Area Integral for Data Curve

From: Roger Stafford

Date: 16 Dec, 2011 17:19:08

Message: 2 of 2

"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

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us