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:
Green's theorem in matlab?

Subject: Green's theorem in matlab?

From: Ray Goldman

Date: 16 Aug, 2010 05:52:05

Message: 1 of 3

hey guys
I posted a message a couple of weeks ago about calculating the area inside a closed curve, well, some guys gave me this formula:
area = 1/2*abs(sum(X.*Y([2:end,1])-Y.*X([2:end,1])));
and it works perfectly, so thanks very much whoever did, sorry I don't remember their name now, I think it's Roger. However, according to my tutor, apparently, I have to explain where I got this formula from in my report. I know it's Green theorem, but I have been searching since and I have got no where on relating it to Green's theorem. now the deadline is tomorrow. so can somebody please just give me a simple explanation how to get from Green's theorem to this numerical representation, I know I'm asking a lot but please just an outline or anything and I'll owe you forever but I'm really desperate right now, thanks guys so much.
Ray

Subject: Green's theorem in matlab?

From: Ross W

Date: 16 Aug, 2010 06:27:06

Message: 2 of 3

"Ray Goldman" <kmmansory@yahoo.com> wrote in message <i4ajm5$4vl$1@fred.mathworks.com>...
> hey guys
> I posted a message a couple of weeks ago about calculating the area inside a closed curve, well, some guys gave me this formula:
> area = 1/2*abs(sum(X.*Y([2:end,1])-Y.*X([2:end,1])));
> and it works perfectly, so thanks very much whoever did, sorry I don't remember their name now, I think it's Roger. However, according to my tutor, apparently, I have to explain where I got this formula from in my report. I know it's Green theorem, but I have been searching since and I have got no where on relating it to Green's theorem. now the deadline is tomorrow. so can somebody please just give me a simple explanation how to get from Green's theorem to this numerical representation, I know I'm asking a lot but please just an outline or anything and I'll owe you forever but I'm really desperate right now, thanks guys so much.
> Ray

One way to think about it is in 2 steps:

1. Get from Green's Theorem to the integral expression that has xdy-ydx in it: see e.g. the equation on http://en.wikipedia.org/wiki/Green's_theorem just below "Possible formulas for the area of D include". Or look at http://mathworld.wolfram.com/GreensTheorem.html

2. Now get from the integral expression to the discrete Matlab formula above.

Do you understand one of these but not the other?

Ross

Subject: Green's theorem in matlab?

From: Roger Stafford

Date: 16 Aug, 2010 07:21:06

Message: 3 of 3

"Ray Goldman" <kmmansory@yahoo.com> wrote in message <i4ajm5$4vl$1@fred.mathworks.com>...
> hey guys
> I posted a message a couple of weeks ago about calculating the area inside a closed curve, well, some guys gave me this formula:
> area = 1/2*abs(sum(X.*Y([2:end,1])-Y.*X([2:end,1])));
> and it works perfectly, so thanks very much whoever did, sorry I don't remember their name now, I think it's Roger. However, according to my tutor, apparently, I have to explain where I got this formula from in my report. I know it's Green theorem, but I have been searching since and I have got no where on relating it to Green's theorem. now the deadline is tomorrow. so can somebody please just give me a simple explanation how to get from Green's theorem to this numerical representation, I know I'm asking a lot but please just an outline or anything and I'll owe you forever but I'm really desperate right now, thanks guys so much.
> Ray
- - - - - - - - - - - -
  I gave you that formula, Ray. Green's theorem is one way, but I think there's an easier way of demonstrating it. Suppose P1 = (x1,y1) and P2 = (x2,y2) are two successive points along a closed polygon as you travel counterclockwise around it. The area of the triangle P1P2O where O is the origin is well known to be one half the cross product of the two vectors pointing from O to P1 and O to P2, and is itself a vector pointing straight up along the z-axis if we are allowing the introduction of a third dimension temporarily. This half cross product is simply (x1*y2-y1*x2)/2. If it is positive that means going P1 to P2 to O and to P1 is counterclockwise. With a negative value it is in the other direction. If you add up all the triangles's areas you will get the expression I gave you.

  If the polygon surrounds the origin then what you have is clearly the polygon's area (if traveling in a counterclockwise direction.) If the origin lies outside the polygon, notice that the triangles' portions that lie outside the polygon are eventually all cancelled out by other triangles returning on the other side of the polygon with negative area values leaving only the area of the polygon itself. It's easier to draw a picture than to put it into words. So draw a picture and see how it works.

  For Green's theorem look up the Wikipedia site at

 http://en.wikipedia.org/wiki/Green's_theorem

at the first equation. Set functions M = x/2 and L = -y/2 and calculate the line integral going along a line segment from P1 to P2 and get, lo and behold, (x1*y2-y1*x2)/2 (after all the smoke clears away.) Adding these all up gives the closed line integral on the left side of that equation. With the given M and L the integral on the right side is simply the double integral over the area of the polygon of the quantity 1/2 - (-1/2) = 1, so it's just the polygon's area itself. QED

  You should realize that Green's theorem as applied here is just a flat two-dimensional version of Stoke's theorem where the vector field has a component of x/2 in the y-axis direction and -y/2 in the direction of the x-axis. The area integral of the curl of this field over the interior of the polygon is simply the integral of 1 over that area and the line integral around the polygon boundary is Stoke's theorem line integral.

Roger Stafford

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