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
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
f | Any | Yes | — | Function of two variables, z = f(x,y). |
xyinterval | NumericArray | No | [-5 5 -5 5] | Two- or four-element domain vector. |
fx | Any | Yes | — | Parametric x-coordinate function. |
fy | Any | Yes | — | Parametric y-coordinate function. |
fz | Any | Yes | — | Parametric z-coordinate function. |
args | Any | Yes | — | Function-handle and optional domain arguments. |
name_value | Any | Variadic | — | MeshDensity and surface style name/value arguments. |
ax | AxesHandle | Yes | — | Target axes handle. |
Returns
| Name | Type | Description |
|---|---|---|
h | NumericScalar | Handle to the rendered function surface. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:fsurf:InvalidArgument | Function handles, domains, mesh density, axes target, or surface properties are invalid. | fsurf: invalid argument |
RunMat:fsurf:EvaluationFailed | A sampled function handle fails or does not return a scalar numeric value. | fsurf: function evaluation failed |
RunMat:fsurf:Internal | Surface construction or rendering fails unexpectedly. | fsurf: internal operation failed |
How fsurf works
fsurf(f)samplesf(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 assurf.
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.
Related Plotting functions
2D Charts
area · bar · errorbar · heatmap · hist · histogram · loglog · pie · plot · scatter · semilogx · semilogy · stairs · stem
Other
addpoints · ancestor · animatedline · axes · barh · cla · clf · colorcube · colororder · copyobj · daspect · datacursormode · dataTipTextRow · fcontour · figure · fill3 · findobj · gobjects · groot · hgload · hgsave · hidden · histogram2 · hold · line · linkaxes · openfig · opengl · pan · parula · patch · plotmatrix · plotyy · polarhistogram · polarplot · polarscatter · print · quiver3 · ribbon · saveas · savefig · sphere · stackedplot · subtitle · suptitle · textscatter · textscatter3 · triplot · waitbar · wordcloud · xline · xscale · xtickangle · xtickformat · xticklabels · xticks · yline · yscale · ytickangle · ytickformat · yticklabels · yticks · zoom
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how fsurf is executed, line by line, in Rust.
- View the source for fsurf in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
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.