3
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ Actually it's a disk in this case. (You probably realize that but, if not, the difference is important.) $\endgroup$ – Daniel Lichtblau Feb 7 '14 at 15:25
  • $\begingroup$ 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. $\endgroup$ – Szabolcs Feb 7 '14 at 20:28
4
$\begingroup$

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]

enter image description here

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

$\endgroup$
  • $\begingroup$ Why not ContourPlot[f[x, y, 0, 0] == 0, {x, -Pi, Pi}, {y, -Pi, Pi}] ? $\endgroup$ – b.gates.you.know.what Feb 7 '14 at 10:18
  • $\begingroup$ 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$. $\endgroup$ – Rahul Feb 7 '14 at 10:23
  • $\begingroup$ 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. $\endgroup$ – Rho Phi Feb 7 '14 at 14:08
  • $\begingroup$ 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. $\endgroup$ – Rho Phi Feb 7 '14 at 14:49
  • 1
    $\begingroup$ 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 ... $\endgroup$ – Szabolcs Feb 7 '14 at 20:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.