%% Integral Over the Unit Sphere in Cartesian Coordinates
% Define the anonymous function f(x,y,z) = x \cos y + x^{2} \cos z.

fun = @(x,y,z) x.*cos(y) + x.^2.*cos(z)

%
% Define the limits of integration.

xmin = -1;
xmax = 1;
ymin = @(x)-sqrt(1 - x.^2);
ymax = @(x) sqrt(1 - x.^2);
zmin = @(x,y)-sqrt(1 - x.^2 - y.^2);
zmax = @(x,y) sqrt(1 - x.^2 - y.^2);

%
% Evaluate the definite integral with the 'tiled' method.

q = integral3(fun,xmin,xmax,ymin,ymax,zmin,zmax,'Method','tiled')

% Copyright 2012 The MathWorks, Inc.