COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Green's theorem in matlab?

• Follow

```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
```
 0

```"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
```
 0
Reply rosswoodskiwi (55) 8/16/2010 6:27:06 AM

```"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
```
 0

2 Replies
446 Views

Similiar Articles:

7/23/2012 2:51:59 PM