# plot some functions versus a third variable [duplicate]

I have three functions as

For w=0.1   y=2 Cos[0.1 x]^2 + Sin[0.1 x]^4
For w=0.5   y=2 Cos[0.5 x]^4 + Sin[0.5 x]^2
For w=0.7   y=3 Cos[0.7 x]^2 + Sin[0.7 x]^4


the desired case for me is to obtain a plot such as below one that for different w I can have y versus x. How can I do that? (I accidentally saw this plot and is not related to my variables. Its configuration just is important to me) here is an answer but my question is different because the real positions for ws is not important. just legends can describe plots.

func[.1, x_] := 2 Cos[0.1 x]^2 + Sin[0.1 x]^4;
func[.5, x_] := 2 Cos[0.5 x]^4 + Sin[0.5 x]^2;
func[.7, x_] := 3 Cos[0.7 x]^2 + Sin[0.7 x]^4;

ParametricPlot3D[{{x, .1, func[.1, x]},
{x, .5, func[.5, x]},
{x, .7, func[.7, x]}},
{x, -2 π, 2 π},
BoxRatios -> {1, 1, 1},
FaceGrids -> {{-1, 0, 0}, {0, 1, 0}},
ViewPoint -> {2, -2.5, .7},
ViewVertical -> {.25, -.33, .9},
AxesLabel -> {"x", "w", "y"},
PlotLegends -> {"w=0.1", "w=0.5", "w=0.7"}] • I am so glad that I can see your answer. If w positions be clear the figure will be better, for example it is not clear what plot is related to w=0.1 and so on (as legends). of course it is not important the exact value of w such as defined @ bill s. for example w=0.1 can be not definitely in w=0.1 Aug 26, 2016 at 13:45
• You can add options to the ParametricPlot3D so as to label the axes, or other such things Aug 26, 2016 at 13:47

Define a function y[x,w] of x and w and then Plot3D.

y[x_, 1/10] := 2 Cos[0.1 x]^2 + Sin[0.1 x]^4
y[x_, 5/10] := 2 Cos[0.5 x]^4 + Sin[0.5 x]^2
y[x_, 7/10] := 3 Cos[0.7 x]^2 + Sin[0.7 x]^4


Here's one way to plot:

ListPointPlot3D[Table[{w, x, y[x, w]}, {x, -10, 10, 0.01}, {w, 1/10, 8/10, 1/10}]] Personally, when dealing with functions depending on a parameter I prefer the notation f[param][vars].

f[w_][x_] := 2 Cos[w x]^2 + Sin[w x]^4


You can plot f vs y for a given value of the parameter w

w0=.5;
Plot[f[w0][x],{x,-6,6}]


Or you can see how changing the parameter alters the value of f for a given x

x0=2;
Plot[f[w][x0],{w, 0.1, 0.9}]


Or you can have the whole she-bang with a Plot3D

Plot3D[f[w][x], {x, -10, 10}, {w, 0.1, 0.8}]


If your parameter has only discrete values, then you can create table of functions and plotting them all in a 2D graph.

funs = Table[f[w][x], {w, 0.1, 0.7, .2}];
Plot[Evaluate[funs], {x, -10, 10}]


Or in a 3D graph using one of the approaches suggested in the other answers. But let me add this procedure, taken from Bahder's "Mathematica for Scientists and Engineers":

LinePlot3D[data_, opts___] := Show[Graphics3D[Line /@ data, opts]]

Its advantage is to be able to work on experimental data. To use functions like the one defined above, you need a simple line to generate the points

data = Table[{x, w, f[w][x]}, {w, 0.1, 0.7, 0.2}, {x, -10, 10, .1}];


and then you can plot the curves

LinePlot3D[data, BoxRatios -> {1, 1, 1}]


Done. (EDIT: I just realized that ListPointPlot3D does what Table and LinePlot3D do, but in a single command - it wasn't there on version 2!)

• I so much like this type of solution Aug 26, 2016 at 18:49