fsurf — Plot scalar or parametric function surfaces.

fsurf evaluates function handles over a rectangular two-variable domain and renders the sampled values as a 3-D surface. It supports ordinary z = f(x,y) surfaces and parametric surfaces supplied as x = fx(u,v), y = fy(u,v), and z = fz(u,v).

Syntax

h = fsurf(f)
h = fsurf(f, xyinterval)
h = fsurf(fx, fy, fz)
h = fsurf(fx, fy, fz, uvinterval)
h = fsurf(___, Name, Value, ...)
h = fsurf(ax, ___)

Inputs

NameTypeRequiredDefaultDescription
fAnyYesFunction of two variables, z = f(x,y).
xyintervalNumericArrayNo[-5 5 -5 5]Two- or four-element domain vector.
fxAnyYesParametric x-coordinate function.
fyAnyYesParametric y-coordinate function.
fzAnyYesParametric z-coordinate function.
argsAnyYesFunction-handle and optional domain arguments.
name_valueAnyVariadicMeshDensity and surface style name/value arguments.
axAxesHandleYesTarget axes handle.

Returns

NameTypeDescription
hNumericScalarHandle to the rendered function surface.

Errors

IdentifierWhenMessage
RunMat:fsurf:InvalidArgumentFunction handles, domains, mesh density, axes target, or surface properties are invalid.fsurf: invalid argument
RunMat:fsurf:EvaluationFailedA sampled function handle fails or does not return a scalar numeric value.fsurf: function evaluation failed
RunMat:fsurf:InternalSurface construction or rendering fails unexpectedly.fsurf: internal operation failed

How fsurf works

  • fsurf(f) samples f(x,y) on the default [-5 5 -5 5] domain.
  • fsurf(f, [xmin xmax ymin ymax]) uses an explicit rectangular domain; a two-element vector applies the same limits to both axes.
  • fsurf(fx, fy, fz) samples a parametric surface over the default parameter domain.
  • fsurf(ax, ___) renders into the requested axes and returns a function-surface graphics handle.
  • Function-handle outputs must be scalar real numeric values at every sampled point; non-finite explicit surface samples are preserved as surface discontinuities.

Options

  • 'MeshDensity' controls the number of samples along each domain dimension. RunMat accepts integer values from 2 through 400.
  • Surface style name/value pairs such as 'DisplayName', 'FaceAlpha', 'FaceColor', 'EdgeColor', 'Shading', 'Lighting', 'Visible', and 'Colormap' use the same parsing path as surf.

Does RunMat run fsurf on the GPU?

Callback sampling runs on the host.

The resulting surface uses the existing runmat-plot surface rendering path.

GPU memory and residency

fsurf is a callback-sampling builtin. It creates a new sampled surface and does not preserve input residency, because the inputs are MATLAB function handles rather than numeric provider buffers.

Examples

Plot a function surface over the default domain

fsurf(@(x,y) sin(x) + cos(y));

Set the domain and mesh density

h = fsurf(@(x,y) x.^2 - y.^2, [-2 2 -1 1], 'MeshDensity', 75, 'DisplayName', 'saddle');

Plot a parametric surface

fx = @(u,v) cos(u).*sin(v);
fy = @(u,v) sin(u).*sin(v);
fz = @(u,v) cos(v);
fsurf(fx, fy, fz, [0 2*pi 0 pi]);

Using fsurf with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how fsurf changes the result.

Run a small fsurf example, explain the result, then change one input and compare the output.

FAQ

Does fsurf evaluate the function handle on the GPU?

No. MATLAB function handles can contain arbitrary user code, so RunMat samples them on the host and then hands the sampled surface to the plotting renderer.

What happens if the function returns a vector?

RunMat raises RunMat:fsurf:EvaluationFailed; each sampled point must produce one scalar numeric value.

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how fsurf is executed, line by line, in Rust.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.

  • RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
  • Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.