Double integrals

> restart; with(plots): with(VectorCalculus):

Warning, the name changecoords has been redefined

Warning, the assigned names <,> and <|> now have a global binding

Warning, these protected names have been redefined and unprotected: *, +, ., D, Vector, diff, int, limit, series

One way of representing a double integral is literally as two nested single integrals.  For example, over a rectangle:

> I1:= int( 4*x-y^2, y=0..2 );

I1 := 8*x-8/3

> I2:= int( I1, x=0..3 );

I2 := 28

If you use Int (capitalized), Maple will not evaluate the integral (the "inert" form).  This way you can see what is going on.

> I1:= Int( 4*x-y^2, y=0..2 );

I1 := Int(4*x-y^2, y = (0 .. 2))

> I2:= Int( I1, x=0..3 );

I2 := Int(Int(4*x-y^2, y = (0 .. 2)), x = (0 .. 3))

Use value to force Maple to do the evaluation.

> value(I2);

28

To save time for all this, however, the VectorCalculus package defines a special syntax for int.

> int( 4*x-y^2, [x,y]=Region(0..3,0..2) );

28

You can also ask for the "inert" form here.

> int( 4*x-y^2, [x,y]=Region(0..3,0..2), 'inert' );

Int(Int(4*x-y^2, y = (0 .. 2)), x = (0 .. 3))

The integrals can be taken with variables in either order. Notice that the "outer" integral is listed first.

> int( 4*x-y^2, [y,x]=Region(0..2,0..3), 'inert' );

Int(Int(4*x-y^2, x = (0 .. 3)), y = (0 .. 2))

Maple can also do integrals over nonrectangular regions.  Some are predefined for you.

> int( x*y, [x,y]=Triangle(<0,0>,<2,0>,<2,1>) );

1/2

> int( 1, [x,y]=Circle(<0,0>,4) );

16*Pi

More generally you need to work out variable limits on the "inner" integral.  For example, to integrate over this region:

> implicitplot( {x=exp(y),x=2}, x=0..2, y=0..ln(2) );

[Plot]

We see that x varies from the value exp(y) to 2, as y varies from 0 to ln(2).  Hence we can use

> int( f(x,y), [y,x]=Region(0..ln(2),exp(y)..2) );

int(int(f(x, y), x = (exp(y) .. 2)), y = (0 .. ln(2)))

An alternative is to do y first.

> int( f(x,y), [x,y]=Region(1..2,0..ln(x)) );

int(int(f(x, y), y = (0 .. ln(x))), x = (1 .. 2))

They have to give the same answer!

> eval(%,f(x,y)=x*y^2), eval(%%,f(x,y)=x*y^2);

2/3*ln(2)^3-ln(2)^2+ln(2)-3/8, 2/3*ln(2)^3-ln(2)^2+ln(2)-3/8

Polar coordinates

From Maple's point of view, there is nothing special about polar integrals.  You must remember to put the extra factor of r in the integrand, and you have to change the limits of integration manually.

For example. consider integrating x^2+y^2 over a quarter-ring domain:

> p1:=implicitplot( {x^2+y^2=1,x^2+y^2=4}, x=0..2, y=0..2):
p2:=plot([ [0,t,t=1..2],[t,0,t=1..2]],color=red):

display({p1,p2},scaling=constrained,axes=frame);

[Plot]

The most natural form of this is in polar coordinates. Note that we have to insert the extra factor of r.

> int( r^2*r, [r,theta]=Region(1..2,0..Pi/2), inert );

Int(Int(r^3, theta = (0 .. 1/2*Pi)), r = (1 .. 2))

> value(%);

15/8*Pi

We could get the same result more awkwardly in rectangular coordinates by breaking into two pieces.

> int( x^2+y^2, [x,y]=Region(0..1,sqrt(1-x^2)..sqrt(4-x^2))) +
int( x^2+y^2, [x,y]=Region(1..2,0..sqrt(4-x^2)));

1/2*3^(1/2)+13/24*Pi-1/4*3^(1/2)*(2-8/9*Pi*3^(1/2))-9/4*3^(1/2)*(1-16/81*Pi*3^(1/2))-3/2*3^(1/2)*(-2+8/27*Pi*3^(1/2))+9/16*3^(1/2)*(-4/3+32/81*Pi*3^(1/2))

> simplify(%);

15/8*Pi

>