% fun_gradient.m — Surface gradient of a scalar function. % % grad differentiates a surfacefun, automatically accounting for the % on-surface metric. It returns the three Cartesian components of the % surface gradient. mip load --install flatironinstitute/flatironinstitute/surfacefun p = 16; nref = 2; dom = surfacemesh.sphere(p + 1, nref); f = surfacefun(@(x, y, z) cos(6*x) .* y + exp(z), dom); [fx, fy, fz] = grad(f); figure(1); subplot(131), plot(fx), title('\partial_x f') subplot(132), plot(fy), title('\partial_y f') subplot(133), plot(fz), title('\partial_z f')