%% Examples: Surface area 

%% (1): Surface area of paraboloid
% Consider the paraboloid given by z=4-x^2-y^2. Find the surface area for -1<=x<=1 and -1<=y<=1. Note that this gives difficult integrals in Cartesian coordinates.
syms x y a real 
f = 4-x^2-y^2 
fx = diff(f,x)
fy = diff(f,y)
g = sqrt(1+fx^2+fy^2)     % integrand for surface area
I1 = int(g,y,-1,1)        % inner integral over y: Matlab can do this
I = int(I1,x,-1,1)        % outer integral over x: Matlab cannot do this, returns int(...)
Id = double(I)            % use double(...) to get numerical answer

ezsurf(f,[-1 1 -1 1])
nice3d

%% (2): Surface area of paraboloid
% Now find the surface area of the paraboloid for (x,y) with x^2+y^2<=4. Use polar coordinates.

syms r theta real
Pi = sym('pi');
X = r*cos(theta); Y = r*sin(theta);
F = simplify(subs(f,{x,y},{X,Y})) % f in polar coordinates, simplify
G = simplify(subs(g,{x,y},{X,Y})) % integrand in polar coordinates, simplify

I1 = int(G*r,r,0,2)       % inner integral, use area element r*dr*dtheta
I = int(I1,theta,0,2*Pi)  % outer integral

ezsurfpol(F,0,2*pi,0,2);
nice3d

