fcontour — Plot contour lines of a scalar function.

fcontour evaluates a function handle over a rectangular two-variable domain and renders contour lines from the sampled values.

Syntax

h = fcontour(f)
h = fcontour(f, xyinterval)
h = fcontour(___, Name, Value, ...)
h = fcontour(ax, ___)

Inputs

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

Returns

NameTypeDescription
hNumericScalarHandle to the rendered function contour.

Errors

IdentifierWhenMessage
RunMat:fcontour:InvalidArgumentFunction handle, domain, mesh density, axes target, levels, or contour properties are invalid.fcontour: invalid argument
RunMat:fcontour:EvaluationFailedA sampled function handle fails or does not return a scalar numeric value.fcontour: function evaluation failed
RunMat:fcontour:InternalContour construction or rendering fails unexpectedly.fcontour: internal operation failed

How fcontour works

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

Options

  • 'MeshDensity' controls the number of samples along each domain dimension. RunMat accepts integer values from 2 through 400.
  • 'LevelList', 'Levels', 'LevelStep', 'LevelListMode', 'LineColor', 'Color', and 'LineWidth' use the same parsing path as contour.
  • 'DisplayName' sets the function-contour graphics handle display name.

Does RunMat run fcontour on the GPU?

Callback sampling runs on the host.

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

GPU memory and residency

fcontour is a callback-sampling builtin. It creates a new sampled contour plot and does not preserve input residency, because the input is a MATLAB function handle rather than a numeric provider buffer.

Examples

Plot function contours over the default domain

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

Set the domain, levels, and mesh density

h = fcontour(@(x,y) x.^2 - y.^2, [-2 2 -1 1], 'LevelList', [-1 0 1], 'MeshDensity', 75);

Using fcontour with coding agents

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

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

FAQ

Does fcontour 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 grid to the contour renderer.

What happens if the function returns a vector?

RunMat raises RunMat:fcontour: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 fcontour 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.