Skip to main content

Section 3.8 Double Integrals for Non-rectangles

In the previous section we considered only integrals over rectangular regions. In practice, regions of interest are rarely rectangles and so in this section we consider two strategies for evaluating integrals over other regions.
Calculus tells us that if the region can be described by simple functions, then we might be able to use iterated integrals. For instance, suppose that \(R\) is the region inside of a circle of radius \(2\text{.}\) Since the boundary of that circle is given by \(x^{2} + y^{2} = 2^{2}\text{,}\) we could express the integral of \(f(x,y)\) on this region by:
\begin{equation*} \int_{-2}^{2} \int_{-\sqrt{4-x^{2}}}^{ \sqrt{4-x^{2}}}f(x,y) \, dy dx\text{.} \end{equation*}
Of course this integral may be complicated, even if \(f(x,y)\) is simple. If \(f(x,y) = x^{2} y^{2}\text{,}\) then
\begin{equation*} \begin{split}\int_{-2}^{2} \int_{-\sqrt{4-x^{2}}}^{ \sqrt{4-x^{2}}}x^{2} y^{2} \, dy dx&= \int_{-2}^{2} \left. x^{2} \frac{y^{3}}{3}\right|_{-\sqrt{4-x^{2}}}^{ \sqrt{4-x^{2}}}\, dx \\&= \frac{2}{3}\int_{-2}^{2} x^{2} (4 - x^{2})^{\frac{3}{2}}\, dx\end{split}\text{.} \end{equation*}
At this point we would need to do a trig substitution to find the value of the integral.

Subsection 3.8.1 Redefining the function

One strategy is to redefine the function so that it is zero outside the region of interest, then integrate over a rectangle that includes the region.
For example, suppose we need to approximate the value of
\begin{equation*} I = \iint_{T} \sin^{3} (xy) \, dx \, dy \end{equation*}
where \(T\) is the triangle with corners at \((0,0)\text{,}\) \((1,0)\) and \((0,2)\text{.}\) Then we could let \(R\) be the rectangle \([0,1] \times [0,2]\) which contains the triangle \(T\text{.}\) Notice that the hypotenuse of the triangle has the equation \(2x + y = 2\text{.}\) Then make \(f(x) = \sin^{3} (xy)\) if \(2x +y \le 2\) and \(f(x) = 0\) if \(2x+y > 2\text{.}\) In MATLAB we can make this function with the command
>> f = @(x,y) sin(x.*y).^3.*(2*x + y <= 2)
In this command <= is a logicalcommand. The term in parentheses is then a logical statementand is given the value 1 if the statement is true and 0 if it is false. We can then integrate the modified f on \([0,1] \times [0,2]\) using the command
>> I = integral2(f,0,1,0,2)
As another example, suppose we need to integrate the function \(f(x,y) = 10+(x-1)(y-2)\) inside the circle of radius 2 centered at \((1,2)\text{.}\) The equation for this circle is \((x-1)^{2} + (y-2)^{2} = 4\text{.}\) Note that the inside of the circle is \((x-1)^{2} + (y-2)^{2} \le 4\) and that the circle is contained in the rectangle \([-1,3] \times [0,4]\text{.}\) Thus we can create the right function, plot it, and integrate it by
>> f = @(x,y) (10+(x-1).*(y-2)).*((x-1).^2 + (y-2).^2 <= 4)
>> [X Y] = meshgrid(-4:0.01:4,-3:0.01:5);
>> Z = f(X,Y);
>> mesh(X,Y,Z)
>> I = integral2(f,-1,3,0,4)

Subsection 3.8.2 Integration Based on Triangles

The second approach to integrating over non-rectangular regions is based on subdividing the region into triangles. Such a subdivision is called a triangulation. On regions where the boundary consists of line segments, this can be done exactly. Even on regions where the boundary contains curves, this can be done approximately. This is a very important idea for several reasons, the most important of which is that the finite elements method is based on it. Another reason this is important is that often the values of \(f\) are not given by a formula, but from data. For example, suppose you are surveying on a construction site and you want to know how much fill will be needed to bring the level up to the plan. You would proceed by taking elevations at numerous points across the site. However, if the site is irregularly shaped or if there are obstacles on the site, then you cannot make these measurements on an exact rectangular grid. In this case, you can use triangles by connecting your points with triangles. Many software packages will even choose the triangles for you (MATLAB will do it using the command delaunay).
The basic idea of integrals based on triangles is exactly the same as that for rectangles; the integral is approximated by a sum where each term is a value times an area
\begin{equation*} I \approx \sum_{i=1}^{n} f(x^{*}_{i}) A_{i}\text{,} \end{equation*}
where \(n\) is the number of triangles, \(A_{i}\) is the area of the triangle and \(x^{*}\) a point in the triangle. However, rather than considering the value of \(f\) at just one point people often consider an average of values at several points. The most convenient of these is of course the corner points. We can represent this sum by
\begin{equation*} T_{n} = \sum_{i=1}^{n} \bar{f}_{i} A_{i}\text{,} \end{equation*}
where \(\bar{f}\) is the average of \(f\) at the corners.
If the triangle has vertices \((x_{1},y_{1})\text{,}\) \((x_{2},y_{2})\) and \((x_{3},y_{3})\text{,}\) the formula for area is
\begin{equation*} A = \frac{1}{2}\left| \text{det}\left( \begin{array}{ccc}x_1 &x_2 &x_3\\ y_1 &y_2 &y_3\\ 1 &1 &1\\\end{array} \right) \right|\text{.} \end{equation*}
The function below implements this method.
Program 3.8.1. mythreecorners
function  I = mythreecorners(f,V,T)
    % Integrates a function based on a triangulation, using three corners
    % Inputs: f -- the function to integrate
    %         V -- the vertices. 
    %              Each row has the x and y coordinates of a vertex
    %         T -- the triangulation. 
    %              Each row gives the indices of the three corners
    % Output: the approximate integral
    x = V(:,1); % extract x and y coordinates of all nodes
    y = V(:,2);
    I=0;                % start accumulator at 0     
    p = size(T,1);      % get number of triangles
    for i = 1:p         % loop through the triangles
       x1 = x(T(i,1));  % find coordinates of the three corners
       x2 = x(T(i,2));
       x3 = x(T(i,3));
       y1 = y(T(i,1));
       y2 = y(T(i,2));
       y3 = y(T(i,3));
       A = .5*abs(det([x1, x2, x3; y1, y2, y3; 1, 1, 1])); %find area
       z1 = f(x1,y1);  % find values at the three corners
       z2 = f(x2,y2);
       z3 = f(x3,y3);
       zavg = (z1 + z2 + z3)/3;  % average the values
       I = I + zavg*A;   % accumulate integral
    end
end
Another idea would be to use the center point (centroid) of each triangle. If the triangle has vertices \((x_{1},y_{1})\text{,}\) \((x_{2},y_{2})\) and \((x_{3},y_{3})\text{,}\) then the centroid is given by the simple formulas
\begin{equation*} \bar{x}= \frac{x_{1} + x_{2} + x_{3}}{3}\quad\text{and}\quad \bar{y}= \frac{y_{1} + y_{2} + y_{3}}{3}\text{.} \end{equation*}

Exercises 3.8.3 Exercises

1.

  1. Download the program mywasher.m (Program A.2.8). Plot \(f(x,y) = \frac{x+y}{x^{2}+y^{2}}\) on the region produced by mywasher.m and use the program mythreecorners.m (Program 3.8.1) to calculate the integral of \(f\) on the washer. Is this accurate? How do you know?
  2. Download the program mywedge.m (Program A.2.9). Plot \(g(x,y) = \sin(x) + \sqrt{y}\) on the region produced by mywedge.m. Use mythreecorners.m (Program 3.8.1) to calculate the integral of \(g\) on this wedge.

2.

Modify the program mythreecorners.m (Program 3.8.1) to a new program mycenters.m that does the centerpoint method for triangles. Run the program on the region produced by mywasher.m (Program A.2.8) with the function \(f(x,y) = \frac{x+y}{x^{2}+y^{2}}\) and on the region produced by mywedge.m (Program A.2.9) with the function \(g(x,y) = \sin(x) + \sqrt{y}\text{.}\)