19 January 2016

Suppose you want to plot a function g depending on two variables x, y over a range where y depends on x.

Using Mathematica this can be done in essentially one line (not counting the definition of the function g and the lower and upper bounds f1 and f2).

f1[y_] := y^3 - 1
f2[y_] := y^3 + 1
g[x_, y_] := x^2 + y^2

Plot3D[g[x, y], {x, -2, 2}, {y, -2, 2}, RegionFunction -> Function[{x, y, z}, f1[x] < y < f2[x]]]

The output will be like this.

Mathematica output

I am not aware of an equivalent function built directly into MATLAB. However, the same functionality can be achieved with some manual coding.

The essential idea is to create a surface in 3D space and plot this using MATLAB’s surf function. I put the code in a gist, which you can find/fork/comment here.

The output looks like this.

MATLAB output



blog comments powered by Disqus