# ParametricPlot3D with variable plot limits

I would like to use ParametricPlot3D in the following general way:

ParametricPlot3D[\[Sigma][u,v],{u,0,2Pi},{v,-f[u],f[u]}].


The problem is that my specific function f[u] is defined via a numerical procedure (NMinimize). Hence, although I obtain the desired plot, I also get some error messages.

Below is an example. (The specifics of the function f[u] are totally unimportant, I just cooked it up.)

\[Sigma][u_, v_] = {Cos[u], Sin[u], v}

f[u_] := Evaluate[
v /. First[NDSolve[{v'[t] == 0, v[0] == u}, v, {t, 0, 2 Pi}]]][0]

ParametricPlot3D[\[Sigma][u, v], {u, 0, 2 Pi}, {v, -f[u], f[u]}]


Question: What is the best way to avoid the error messages displayed below? I am aware about the possibility of using RegionFunction, but I am curious to know whether it can be avoided.

ReplaceAll::reps: {(v^\[Prime])[t]==0,v[0]==u} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing.

NDSolve::ndinnt: Initial condition u is not a number or a rectangular array of numbers.

ReplaceAll::reps: {(v^\[Prime])[t]==0,v[0]==u} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing.

ReplaceAll::argx: ReplaceAll called with 2 arguments; 1 argument is expected.

ReplaceAll::reps: {(v^\[Prime])[t]==0.,v[0.]==u} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing.

General::stop: Further output of ReplaceAll::reps will be suppressed during this calculation.

ReplaceAll::argx: ReplaceAll called with 2 arguments; 1 argument is expected.

NDSolve::ndinnt: Initial condition u is not a number or a rectangular array of numbers.

ReplaceAll::argx: ReplaceAll called with 2 arguments; 1 argument is expected.

General::stop: Further output of ReplaceAll::argx will be suppressed during this calculation.

NDSolve::ndinnt: Initial condition u is not a number or a rectangular array of numbers.

General::stop: Further output of NDSolve::ndinnt will be suppressed during this calculation.


Consider the function:

f[u_] :=
Evaluate[v /.
First[NDSolve[{v'[t] == 0, v[0] == u}, v, {t, 0, 2 Pi}]]][0]


Note, it does not make sense to use ":=" and "Evaluate" together. Either you want instantaneous evaluation, then use "=" or if you want delayed evaluation, then use ":=".

Further, your ODE says v'[t]==0, that means v does not change and because v[0]==u, then v[t]=u. And f[u_]=u. That means, we do not need f[u] at all. With this we have:

\[Sigma][u_, v_] = {Cos[u], Sin[u], v}
ParametricPlot3D[\[Sigma][u, v], {u, 0, 2 Pi}, {v, -u, u}]


• Thanks a lot for your reply. I only defined that function to illustrate the problem using as little code as possible. The one I am dealing with in reality involves NMinimize and cannot be evaluated before the ParametricPlot3D line. Commented May 25, 2021 at 19:57
• Define: f[u_?NumericQ]=... Commented May 25, 2021 at 20:10
• That solves my issue, thanks! Commented May 26, 2021 at 8:01