Example Lecture 4.3
Integral of xy over triangle
Contents
Cut-off function
The function T is a boolean function, which is =1 (true) on the triangle and =0 (false) outside the triangle.
T=@(x,y) (0<=x).*(x<=1).*(0<=y).*(y<=x); x=linspace(-1,2); [X,Y]=meshgrid(x,x); Z=T(X,Y); surfc(X,Y,Z)

Computation of the integral
f=@(x,y) (x.*y); % the integrand fT=@(x,y) (f(x,y).*T(x,y)); % the cut-off integrand I=integral2(fT,0,1,0,1) % integration over rectangle
Warning: Reached the maximum number of function evaluations (10000). The result fails the global error test. I = 0.1250
Computation of the integral
The function T is unnecessarily complicated. This is enough:
T=@(x,y) (y<=x); f=@(x,y) (x.*y); % the integrand fT=@(x,y) (f(x,y).*T(x,y)); % the cut-off integrand I=integral2(fT,0,1,0,1) % integration over rectangle
Warning: Reached the maximum number of function evaluations (10000). The result fails the global error test. I = 0.1250