# project from a n-dimensional space to 2-dim

let's say that I have a sphere in $N$-dimensions

$$x_1^2+x_2^2+...+x_N^2=R$$

If I want to know the projection on the $x_1-x_2$ plane in this case I can figure out myself that is a circle, but how can I get Mathematica to do the projection and plot it for me?

Of course I need to apply this to a more complicated case where the N-dimensional surface is not as simple and can only be defined implicitly by $f(x_1,...,x_N)=0$.

I hope I have not forgot too much math from school that I am asking mathematica to do this for me.

• Actually it's a disk in this case. (You probably realize that but, if not, the difference is important.) Commented Feb 7, 2014 at 15:25
• Can you give an example of an actual function you plan to work with? The $n$-sphere is trivial, but your actual problem might still have some structure to it that will make it easier to solve than the completely general case. Commented Feb 7, 2014 at 20:28

Here's an approach using FindInstance and RegionPlot. Unfortunately it is incredibly slow.

A funky function for us to test on:

f[x_, y_, z_, w_] := Sin[x] Cos[y] + Sin[y] Cos[z] + Sin[z] Cos[w] + Sin[w] Cos[x] - 1


Check whether a point $(x,y)$ corresponds to a solution $f(x,y,z,w)=0$ for some $z$ and $w$:

g[x_?NumericQ, y_?NumericQ] := Length@FindInstance[f[x, y, z, w] == 0, {z, w}, Reals] > 0


Plot the region where $g(x,y)$ is True:

RegionPlot[g[x, y], {x, -Pi, Pi}, {y, -Pi, Pi}, PlotPoints -> 5, MaxRecursion -> 1]


Even with PlotPoints and MaxRecursion turned way down it takes like ten minutes to create the plot.

• Why not ContourPlot[f[x, y, 0, 0] == 0, {x, -Pi, Pi}, {y, -Pi, Pi}] ? Commented Feb 7, 2014 at 10:18
• My understanding of the question is we want the projection of the entire set $f(x,y,z,w)=0$ onto the $xy$ plane, not a slice through the $xy$ plane. That is, if $f(1,1,1,1)=0$ then $(1,1)$ should be included in the plot even if $f(1,1,0,0)\ne0$.
– user484
Commented Feb 7, 2014 at 10:23
• As said by Rahul I need not to just plot a slice, but the entire projection. For the N-sphere it would be a filled circle, not the perimeter of a circumference of some radius. The FindInstance is a good function to think about for this issue and the proposed example is at least food for thoughts, thanks. Commented Feb 7, 2014 at 14:08
• I see that the function gets incredibly slower as the number of dimensions increases. I am wondering if putting some more information in the game could help. For instance my function is Likelyhood, so I know that there is a maximum at a given point that is contained in the area that will result from the projection. I was thinking to use this information by drawing the projection with a random shot of points starting from a seed based of the location of the maximum point. This, I think, should scale much more friendly when one increases the number of dimensions that are projected out. Commented Feb 7, 2014 at 14:49
• Show@Table[ ContourPlot[f[x, y, z, w] == 0, {x, -3, 3}, {y, -3, 3}], {z, -3, 3, .3}, {w, -3, 3, .3}] gives some hints about the shape and it's much faster. Of course it's far from precise ... Commented Feb 7, 2014 at 20:48