concept-collection / numbl-surfacefun-intro
numbl-surfacefun-intro / vec_gradient.m
20 lines · 595 BBlameHistoryRaw
1% vec_gradient.m — The surface gradient as a vector field.
2%
3% grad(f) of a surfacefun is a surfacefunv. The gradient is tangent to
4% the surface, as the quiver plot shows.
6mip load --install flatironinstitute/flatironinstitute/surfacefun
8rng(0)
9p = 16;
10nref = 2;
11dom = surfacemesh.blob(p + 1, nref);
13f = surfacefun(@(x, y, z) cos(6*x) .* y + exp(z), dom);
15figure(1);
16quiver(grad(f), 0.05, 6)
17title('Surface gradient of f (tangent to the surface)');
19% Identity: the divergence of the gradient is the Laplacian.
20fprintf('|| div(grad f) - lap(f) || = %.3e\n', norm(div(grad(f)) - lap(f)));