Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Area Between Contours in ContourPlot

132 views
Skip to first unread message

John.Ho...@csiro.au

unread,
Feb 26, 2003, 3:02:03 AM2/26/03
to
Hi All

I am new to Mathematica and am wondering if someone on the list would be
kind enough to help me out. I have a contourplot of a function and wish to
find the area between certain contours contained within the plot. Is there a
standard function in Mathematica which will do this? If not I would
appreciate any suggestions on how I should go about doing this with
Mathematica, I'm using version 4.2.

Thanks in advance for your time and help.

Cheers John

John Hornbuckle
CSIRO Land and Water
PMB No. 3, Griffith,
NSW, 2680
Australia

Tel. (02) 69601500
Fax. (02) 69601600

Selwyn Hollis

unread,
Feb 27, 2003, 12:57:14 AM2/27/03
to
John,

It may be helpful to think about the example of computing the area of
the "polar rectangle" bounded by

f(x,y) = r^2 < f(x,y) = R^2, g(x,y) = m1 < g(x,y) = m2

where f(x,y) = x^2 + y^2 and g(x,y) = y/x. The region is the image of
the rectangle

G = { (u,v) : r^2 < u < R^2, m1 < v < m2 } ,

under the transformation

T(u,v) = ( Sqrt[u] v/Sqrt[1+v^2], Sqrt[u]/Sqrt[1+v^2])

(Get that by solving u == f(x,y), v == g(x,y), for x and y.)

The area of the region is the integral over G of the absolute value of
the determinant of the Jacobian of T, which here turns out to be
1/(1+v^2).

Integrate[ 1/(2(1+v^2)), {u,r^2,R^2}, {v,m1,m2}]

The result is 1/2 (R^2 - r^2)(ArcTan[m2] - ArcTan[m1]), which coincides
with the usual formula.

More generally, if you want the area of a "patch" defined by

f(x,y) = c1 < f(x,y) = c2, g(x,y) = c3 < g(x,y) = c4,

solve (if possible ) u == f(x,y), v == g(x,y), for x and y, compute the
Jacobian determinant in terms of u and v, then integrate its absolute
value over c1 < u < c2, c3 < v < c4. A sometimes convenient
alternative method for getting the Jacobian determinant is to take the
reciprocal of the Jacobian determinant of the inverse transformation
Tinv(x,y) = (f(x,y), g(x,y)), expressed in terms of u and v.

Hope this helps...

----
Selwyn Hollis


On Wednesday, February 26, 2003, at 02:43 AM, John.Ho...@csiro.au
wrote:

Paul Abbott

unread,
Feb 28, 2003, 4:37:52 AM2/28/03
to
In article <b3hs9r$iko$1...@smc.vnet.net>, John.Ho...@csiro.au wrote:

> I have a contourplot of a function and wish to find the area between certain
> contours contained within the plot. Is there a standard function in
> Mathematica which will do this?

There is no standard function to do this. However, it is not too hard to
do what you want. Here is a contour plot.

cp = ContourPlot[x^4 + 2x y + y^2, {x, -2, 2}, {y, -3, 3},
Contours -> {1/2, 1, 2}, PlotPoints -> 100];

First we need to extract the contour lines from this plot, as a set of
points.

contours = Cases[Graphics[cp], Line[a__] :> a, Infinity]

Then we compute the (approximate) area enclosed within each (closed)
contour by triangulation:

(#[[All,1]] . RotateLeft[#[[All,2]]] -
#[[All,2]] . RotateLeft[#[[All,1]]])/2 & ) /@ contours

Note that the PlotPoints option controls how many points there are in
each contour.

Cheers,
Paul

--
Paul Abbott Phone: +61 8 9380 2734
School of Physics, M013 Fax: +61 8 9380 1014
The University of Western Australia (CRICOS Provider No 00126G)
35 Stirling Highway
Crawley WA 6009 mailto:pa...@physics.uwa.edu.au
AUSTRALIA http://physics.uwa.edu.au/~paul


0 new messages