Functions and vector fields

Once a surface mesh has been constructed, we may define scalar functions and vector fields on the surface.

Scalar functions

The fundamental object which represents a scalar function on a surface is a surfacefun. A surfacefun may be constructed from a function handle representing a given function in Cartesian \((x,y,z)\) coordinates on a given surfacemesh:

f = surfacefun(@(x,y,z) cos(6*x).*y + exp(z), dom)
f =

  surfacefun with properties:

    domain: [1×1 surfacemesh]
      vals: {96×1 cell}

Let’s plot the function:

plot(f), hold on, plot(dom), colorbar
_images/func.png

Many standard MATLAB arithmetic functions have been overloaded.

x = surfacefun(@(x,y,z) x, dom);
g = abs(f + 2*x);
plot(g), colorbar
_images/func_arith.png

We can also visualize a surfacefun using a contour plot:

contour(f, linewidth=2)
axis off
_images/contour.png

We may numerically differentiate a function using the built-in diff or grad routines, which automatically take into account the on-surface metric. For example:

[fx, fy, fz] = grad(f);
subplot(131), plot(fx)
subplot(132), plot(fy)
subplot(133), plot(fz)
_images/diff_func.png

Higher-order derivatives may be constructed by composing these operations. For example, here is the surface Laplacian—or the Laplace–Beltrami operator—applied to our function:

plot(lap(f)), colorbar
_images/func_lap.png

The definite integral of a function over the surface is given by:

integral(f)
ans =

  20.413449092485330

Similarly, the mean of the function is the integral of the function divided by the surface area:

mean(f)
ans =

   1.111334042648337

Norms

The \(L^2\) norm of a surfacefun may be computed via:

norm(f)
ans =

   5.947309239751656

Other norms are implemented as well. The \(L^\infty\) norm is computed via:

norm(f, inf)
ans =

   3.229329881902320

Vector fields

The surfacefunv object represents a three-component vector field over a surfacemesh. Each component is itself represented as a scalar surfacefun.

Let’s make quiver plot of the normal vectors over our surface. We’ll plot 6 vectors per patch and scale their lengths by 0.2:

v = normal(dom);
quiver(v, 0.2, 6)
_images/vec_normals.png

The surface gradient of a surfacefun is a surfacefunv:

grad(f)
ans =

  surfacefunv with properties:

      components: {1×3 cell}
    isTransposed: 0

The gradient is tangent to the surface, as we can see from a quiver plot:

quiver(grad(f), 0.05, 6)
_images/vec_grad.png

The surface divergence of the surface gradient is equal to the surface Laplacian:

norm(div(grad(f)) - lap(f))
ans =

      0

The mean curvature of a surface can be related to its the normal vector field via the surface divergence:

plot(div(v)/2)
_images/vec_div.png

We can also take the surface curl of a surfacefunv:

v = surfacefunv(@(x,y,z) cos(2*x), ...
                @(x,y,z) sin(4*y), ...
                @(x,y,z) sin(3*z), dom);
quiver(curl(v), 0.1, 6)
_images/vec_curl.png