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:
calculate the area of a curve

Subject: calculate the area of a curve

From: angelina

Date: 23 Mar, 2013 13:57:07

Message: 1 of 11

Hi!
I am not sure if there is a way to calculate the area of a curve in matlab.What I want to do , is first , define the curve (which is a load duration curve) and it is three piece linear.How can I define it?
The coordinates are (0,100) , (2.8,75) and (100,25)
Then , I want for the beginning to calculate the whole area af the curve and after that for many straight lines of the form y=a I want to calculate the area of the two areas that are created.
Any comment or help woould be of great importance!
Thanks a lot!

Subject: calculate the area of a curve

From: Nasser M. Abbasi

Date: 23 Mar, 2013 15:03:23

Message: 2 of 11

On 3/23/2013 7:57 AM, angelina wrote:
> Hi!
> I am not sure if there is a way to calculate the area of a curve in matlab.

curve does not have an area. it is just a curved line. it has a length though
and it has curvature, but area?

>What I want to do , is first , define the curve (which is a load duration
>curve) and it is three piece linear.How can I define it?
> The coordinates are (0,100) , (2.8,75) and (100,25)
> Then , I want for the beginning to calculate the whole area af
>the curve and after that for many straight lines of the form y=a I want
>to calculate the area of the two areas that are created.
> Any comment or help woould be of great importance!
> Thanks a lot!
>


It sounds like you want to integrate a function and you have
only 3 points for it? May be you can look at trapz.

http://www.mathworks.com/help/matlab/ref/trapz.html

"Z = trapz(Y) computes an approximation of the integral of Y via the trapezoidal method"

good luck,

--Nasser

Subject: calculate the area of a curve

From: angelina

Date: 23 Mar, 2013 18:02:05

Message: 3 of 11

"Nasser M. Abbasi" wrote in message <kikco2$ops$1@speranza.aioe.org>...
> On 3/23/2013 7:57 AM, angelina wrote:
> > Hi!
> > I am not sure if there is a way to calculate the area of a curve in matlab.
>
> curve does not have an area. it is just a curved line. it has a length though
> and it has curvature, but area?
>
> >What I want to do , is first , define the curve (which is a load duration
> >curve) and it is three piece linear.How can I define it?
> > The coordinates are (0,100) , (2.8,75) and (100,25)
> > Then , I want for the beginning to calculate the whole area af
> >the curve and after that for many straight lines of the form y=a I want
> >to calculate the area of the two areas that are created.
> > Any comment or help woould be of great importance!
> > Thanks a lot!
> >
>
>
> It sounds like you want to integrate a function and you have
> only 3 points for it? May be you can look at trapz.
>
> http://www.mathworks.com/help/matlab/ref/trapz.html
>
> "Z = trapz(Y) computes an approximation of the integral of Y via the trapezoidal method"
>
> good luck,
>
> --Nasser
>

Hi Nasser!
Thanks for your reply!
It seems that I didn't explain correctly.

What I want to do is this:
I have that:

 X=[0 ; 0.028; 1;];
 Y=[1; 0.75; 0.25;];
 plot(X,Y);
So if you plot this thing imagine that I want to find the area between the line and the axes x and y.After that for any line of the form y=g I want to find again the area between the line y=g y=-ax+, my initial line and the axes x and y .
Thank you! I hope now I explained welll!
I am waiting for any reply!
Angelina

Subject: calculate the area of a curve

From: dpb

Date: 23 Mar, 2013 18:22:29

Message: 4 of 11

On 3/23/2013 1:02 PM, angelina wrote:
> "Nasser M. Abbasi" wrote in message <kikco2$ops$1@speranza.aioe.org>...
>> On 3/23/2013 7:57 AM, angelina wrote:
>> > Hi!
>> > I am not sure if there is a way to calculate the area of a curve in
>> matlab.
>>
>> curve does not have an area. it is just a curved line. it has a length
>> though
>> and it has curvature, but area?
>>
>> >What I want to do , is first , define the curve (which is a load
>> duration
>> >curve) and it is three piece linear.How can I define it?
>> > The coordinates are (0,100) , (2.8,75) and (100,25)
>> > Then , I want for the beginning to calculate the whole area af
>> >the curve and after that for many straight lines of the form y=a I want
>> >to calculate the area of the two areas that are created.
>> > Any comment or help woould be of great importance!
>> > Thanks a lot!
>> >
>>
>>
>> It sounds like you want to integrate a function and you have
>> only 3 points for it? May be you can look at trapz.
>>
>> http://www.mathworks.com/help/matlab/ref/trapz.html
>>
>> "Z = trapz(Y) computes an approximation of the integral of Y via the
>> trapezoidal method"
>>
>> good luck,
>>
>> --Nasser
>>
>
> Hi Nasser!
> Thanks for your reply!
> It seems that I didn't explain correctly.
>
> What I want to do is this:
> I have that:
>
> X=[0 ; 0.028; 1;];
> Y=[1; 0.75; 0.25;];
> plot(X,Y);
> So if you plot this thing imagine that I want to find the area between
> the line and the axes x and y.After that for any line of the form y=g I
> want to find again the area between the line y=g y=-ax+, my initial line
> and the axes x and y .
> Thank you! I hope now I explained welll!
> I am waiting for any reply!
> Angelina

Well, for the line segments the area is analytically computable but
trapz() will work. Simply subtract the area of the lower curve(s) from
the upper.

--

Subject: calculate the area of a curve

From: angelina

Date: 23 Mar, 2013 20:25:06

Message: 5 of 11

dpb <none@non.net> wrote in message <kikrt1$3o6$2@speranza.aioe.org>...
> On 3/23/2013 1:02 PM, angelina wrote:
> > "Nasser M. Abbasi" wrote in message <kikco2$ops$1@speranza.aioe.org>...
> >> On 3/23/2013 7:57 AM, angelina wrote:
> >> > Hi!
> >> > I am not sure if there is a way to calculate the area of a curve in
> >> matlab.
> >>
> >> curve does not have an area. it is just a curved line. it has a length
> >> though
> >> and it has curvature, but area?
> >>
> >> >What I want to do , is first , define the curve (which is a load
> >> duration
> >> >curve) and it is three piece linear.How can I define it?
> >> > The coordinates are (0,100) , (2.8,75) and (100,25)
> >> > Then , I want for the beginning to calculate the whole area af
> >> >the curve and after that for many straight lines of the form y=a I want
> >> >to calculate the area of the two areas that are created.
> >> > Any comment or help woould be of great importance!
> >> > Thanks a lot!
> >> >
> >>
> >>
> >> It sounds like you want to integrate a function and you have
> >> only 3 points for it? May be you can look at trapz.
> >>
> >> http://www.mathworks.com/help/matlab/ref/trapz.html
> >>
> >> "Z = trapz(Y) computes an approximation of the integral of Y via the
> >> trapezoidal method"
> >>
> >> good luck,
> >>
> >> --Nasser
> >>
> >
> > Hi Nasser!
> > Thanks for your reply!
> > It seems that I didn't explain correctly.
> >
> > What I want to do is this:
> > I have that:
> >
> > X=[0 ; 0.028; 1;];
> > Y=[1; 0.75; 0.25;];
> > plot(X,Y);
> > So if you plot this thing imagine that I want to find the area between
> > the line and the axes x and y.After that for any line of the form y=g I
> > want to find again the area between the line y=g y=-ax+, my initial line
> > and the axes x and y .
> > Thank you! I hope now I explained welll!
> > I am waiting for any reply!
> > Angelina
>
> Well, for the line segments the area is analytically computable but
> trapz() will work. Simply subtract the area of the lower curve(s) from
> the upper.
>
> --
Thank you Nasser,
I have done this:
X=[0 ; 0.028; 1;];
Y=[1; 0.75; 0.25;
plot(X,Y);
Z=trapz(X,Y);

How can I define a line segment which is parallel to the x axis and has a length that begins from the y axis and ends at the intersection with my initial curve???

Subject: calculate the area of a curve

From: Nasser M. Abbasi

Date: 23 Mar, 2013 22:29:59

Message: 6 of 11

On 3/23/2013 2:25 PM, angelina wrote:

> I have done this:
> X=[0 ; 0.028; 1;];
> Y=[1; 0.75; 0.25;
> plot(X,Y);
> Z=trapz(X,Y);
>
> How can I define a line segment which is parallel to
>the x axis and has a length that begins from the y axis
>and ends at the intersection with my initial curve???
>

equation of the second line which is parallel to the x-axis
is y=constant.

So if you know this constant, then you can find the intersection
point (i.e. the x-coordinate of the intersection point, since
you have the y-coordinate allready in this case) by plugging
this value of the constant for 'y' in the first line equation
and solve for 'x'.

--Nasser

Subject: calculate the area of a curve

From: angelina

Date: 23 Mar, 2013 23:17:07

Message: 7 of 11

"Nasser M. Abbasi" wrote in message <kil6td$3o2$1@speranza.aioe.org>...
> On 3/23/2013 2:25 PM, angelina wrote:
>
> > I have done this:
> > X=[0 ; 0.028; 1;];
> > Y=[1; 0.75; 0.25;
> > plot(X,Y);
> > Z=trapz(X,Y);
> >
> > How can I define a line segment which is parallel to
> >the x axis and has a length that begins from the y axis
> >and ends at the intersection with my initial curve???
> >
>
> equation of the second line which is parallel to the x-axis
> is y=constant.
>
> So if you know this constant, then you can find the intersection
> point (i.e. the x-coordinate of the intersection point, since
> you have the y-coordinate allready in this case) by plugging
> this value of the constant for 'y' in the first line equation
> and solve for 'x'.
>
> --Nasser
>
Dear Nasser,
Thanks for all the replies and the help.And sorry for all these silly questions.
The thing is , that for the first line I don't have the equation.I only have the three points .Is there a way to find it in Matlab?
Or If I find the equations of its segments (because it is threepiece linear) by myself , how can I declare it in matlab?
Also, for the line segment that I asked in the previous question,
if for example I have y=45, how can I plot this line at the same graph as my initial line?
I did not really got it, how I can find the x coordinate of the intersection.
Thanks,
Angelina

Subject: calculate the area of a curve

From: dpb

Date: 23 Mar, 2013 23:24:29

Message: 8 of 11

On 3/23/2013 6:17 PM, angelina wrote:
...

> The thing is , that for the first line I don't have the equation.I only
> have the three points .Is there a way to find it in Matlab?

How would you find it given the points using pencil and paper? That
should give you an idea of how to find it using Matlab.

Do you know a priori the points are identically on a straight line or is
this a regression problem?

--

Subject: calculate the area of a curve

From: Marc

Date: 24 Mar, 2013 04:24:17

Message: 9 of 11

dpb <none@non.net> wrote in message <kildjc$kpf$1@speranza.aioe.org>...
> On 3/23/2013 6:17 PM, angelina wrote:
> ...
>
> > The thing is , that for the first line I don't have the equation.I only
> > have the three points .Is there a way to find it in Matlab?
>
> How would you find it given the points using pencil and paper? That
> should give you an idea of how to find it using Matlab.
>
> Do you know a priori the points are identically on a straight line or is
> this a regression problem?
>
> --

doc polyfit, polyval for starters for fitting 3 points to a line. Although there are many other ways to do this in Matlab.

doc anonymous function (@ symbol) for user created functions, again many ways to do this as polyval above does, provided the right inputs.

Be adventurous.... I realize that this may seem like a big problem but what you are asking is very straight forward. Take some time, read the documentation and play around in Matlab to solve your problem. I promise, you won't break anything.

Good luck

Subject: calculate the area of a curve

From: dpb

Date: 24 Mar, 2013 12:53:07

Message: 10 of 11

On 3/23/2013 6:24 PM, dpb wrote:
> On 3/23/2013 6:17 PM, angelina wrote:
> ...
>
>> The thing is , that for the first line I don't have the equation.I only
>> have the three points .Is there a way to find it in Matlab?
>
> How would you find it given the points using pencil and paper? That
> should give you an idea of how to find it using Matlab.
>
> Do you know a priori the points are identically on a straight line or is
> this a regression problem?

OK, I looked at the actual data points -- I see it is a segmented curve
you've drawn. OK, one way w/o computing the coefficients of the line in
Matlab (easy enough, of course :) ) to fine your intersection point
would be via

doc interp1

Think of which it is that you're looking for while reading...

--

Subject: calculate the area of a curve

From: angelina

Date: 24 Mar, 2013 14:00:08

Message: 11 of 11

"Marc" wrote in message <kilv5h$lj4$1@newscl01ah.mathworks.com>...
> dpb <none@non.net> wrote in message <kildjc$kpf$1@speranza.aioe.org>...
> > On 3/23/2013 6:17 PM, angelina wrote:
> > ...
> >
> > > The thing is , that for the first line I don't have the equation.I only
> > > have the three points .Is there a way to find it in Matlab?
> >
> > How would you find it given the points using pencil and paper? That
> > should give you an idea of how to find it using Matlab.
> >
> > Do you know a priori the points are identically on a straight line or is
> > this a regression problem?
> >
> > --
>
> doc polyfit, polyval for starters for fitting 3 points to a line. Although there are many other ways to do this in Matlab.
>
> doc anonymous function (@ symbol) for user created functions, again many ways to do this as polyval above does, provided the right inputs.
>
> Be adventurous.... I realize that this may seem like a big problem but what you are asking is very straight forward. Take some time, read the documentation and play around in Matlab to solve your problem. I promise, you won't break anything.
>
> Good luck


?hanks to everyone for your help!!
At last I made it!!
Cheers guys!

Tags for this Thread

No tags are associated with 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