# Plotting 2D image of functions of several variables

I have a function $f: \mathbb{R}^4 \to \mathbb{R}^2$, and I would like to plot the region $f([0,1]^4)$. Writing $f_1(s,t,u,v)$ and $f_2(s,t,u,v)$ for each coordinate of the output I tried using Mathematica's parametric plotter:

ParametricPlot[{f1[s,t,u,v], f2[s,t,u,v]} , {s,0,1}, {t,0,1}, {u,0,1}, {v,0,1}]


This failed because Mathematica seems to only support parametric plotting in (at most) two parameters. Does anyone know of a work around?

For the sake of having a working example, an abbreviated example of my functions is:

f1[s_,t_,u_,v_]:=(s+1/s)(t+1/t)Cos[\[Pi] u/4]Cos[\[Pi] v/4];
f2[s_,t_,u_,v_]:=(s+1/s)(t-1/t)Cos[\[Pi] u/4]Sin[\[Pi] v/4];

-
Related: 13378 – Michael E2 Mar 13 '14 at 19:56

The functions are

f1[s_, t_, u_, v_] := (s + 1/s) (t + 1/t) Cos[Pi u/4] Cos[Pi v/4]
f2[s_, t_, u_, v_] := (s + 1/s) (t - 1/t) Cos[Pi u/4] Sin[Pi v/4]


One obvious feature is that the term (s + 1/s) Cos[Pi u/4] is common to both functions, so changing s and u will just scale the region defined by t and v. The range of values for the term (s + 1/s) Cos[Pi u/4] is:

(s + 1/s) Cos[Pi u/4] /. s | u -> Interval[{0, 1}]

Interval[{1/Sqrt[2], Infinity}]


Let's call that term z and define:

g1[z_, t_, v_] := z (t + 1/t) Cos[Pi v/4]
g2[z_, t_, v_] := z (t - 1/t) Sin[Pi v/4]


Now we can plot the region defined by t and v with a few values of z:

ParametricPlot[
Table[{g1[z, t, v], g2[z, t, v]}, {z, {1/Sqrt[2], 2, 4}}]
, {t, 0, 1}, {v, 0, 1}, Evaluated -> True, Axes -> False,
Mesh -> None, PlotPoints -> 50]


The outermost region is the one with z = 1/Sqrt[2], so we can just set that as a fixed value and plot the region as:

ParametricPlot[{g1[1/Sqrt[2], t, v], g2[1/Sqrt[2], t, v]}, {t, 0, 1}, {v, 0, 1},
Axes -> False, AxesOrigin -> {0, 0}]


-
a big +1 for using some common sense. (I was too lazy to do it:) – Ajasja Jun 4 '13 at 14:33

I think this should work:

f1[s_,t_,u_,v_]:=(s+1/s)(t+1/t)Cos[\[Pi] u/4]Cos[\[Pi] v/4];
f2[s_,t_,u_,v_]:=(s+1/s)(t-1/t)Cos[\[Pi] u/4]Sin[\[Pi] v/4];

data=Partition[Flatten[
Table[{f1[s,t,u,v],f2[s,t,u,v]},{s,0.1,1,0.05},{t,0.1,1,0.05},{u,0,1,0.05},{v,0,1,0.05}]
],2];
Dimensions@data

ListPlot@data
SmoothDensityHistogram@data


-
Thanks that works great! – Bob Jun 4 '13 at 11:18

As an alternative, you could plot it parametrically in 2 of the variables and use a slider to control the other two variables. For example

f1[s_, t_, u_, v_] := (s + 1/s) (t + 1/t) Cos[\[Pi] u/4] Cos[\[Pi] v/4];
f2[s_, t_, u_, v_] := (s + 1/s) (t \[Minus] 1/t) Cos[\[Pi] u/4] Sin[\[Pi] v/4];
Manipulate[
ParametricPlot[{f1[s, t, u, v], f2[s, t, u, v]}, {u, 0, 1}, {v, 0, 1},
ImageSize -> {400, 400}], {s, 0.001, 1}, {t, 0.001, 1}]


Or, somewhat easier to control is to place the two manually controlled vairables in a 2D controller (here the s and t variables are replaced by the two dimensions of the slider).

Manipulate[ParametricPlot[{f1[s[[1]], s[[2]], u, v], f2[s[[1]], s[[2]], u, v]},
{u, 0, 1}, {v, 0, 1}, ImageSize -> {400, 400}], {s, {0.001, 0.001}, {1, 1}}]


Or, you could control the u,v manually and have the plot be over the {s,t}.

-