4
$\begingroup$

I want to plot a function $f:\mathbb R^n \rightarrow \mathbb R$ restricted to a domain $D \subset \mathbb R^n$. The domain $D$ is usually specified as the set of zeros for a set of polynomial equations (i.e. an algebraic variety). For example consider the function $f(x,y) = x^{39}y^{63}$ on the ellipse $D := \left\{(x,y)\ \ \big|\ x^2+xy+y^2-1=0\right\}$. How would I plot this for example in Mathematica? (I am on version 7.0.)

$\endgroup$
5
  • 2
    $\begingroup$ You could add an option:RegionFunction->(...) $\endgroup$
    – WateSoyan
    Jun 1, 2015 at 15:25
  • $\begingroup$ Great! That was easy! Thanks $\endgroup$ Jun 1, 2015 at 15:28
  • $\begingroup$ It doesn't seem to work: Plot3D[x^39*y^63, {x, 0, 1}, {y, 0, 1}, RegionFunction -> Function[{x, y}, x^2 + y^2 + x*y == 1]] $\endgroup$ Jun 1, 2015 at 15:31
  • $\begingroup$ And also -- read this (83692) $\endgroup$
    – Sektor
    Jun 1, 2015 at 15:59
  • 2
    $\begingroup$ That's because the 'region' you're plotting in is actually just an infinitesimally thin line. Try Plot3D[x^39*y^63, {x, 0, 1}, {y, 0, 1}, RegionFunction -> Function[{x, y}, x^2 + y^2 + x*y <=1&&x^2 + y^2 + x*y >0.9],PlotRange->All]. It isn't exactly what you want, but it'll show you what the problem is. I think you'd be better off with a different representation of your problem. ParametricPlot3D might work. $\endgroup$
    – N.J.Evans
    Jun 1, 2015 at 16:09

1 Answer 1

10
$\begingroup$

This is the closest way I can imagine to get what you were originally trying to get, though it still may not be the best way to plot what you care about.

First get a parametric representation of y in terms of x.

y[x_]=y/.Solve[x^2 + x*y + y^2 == 1, y,Reals];

Then make a parametric plot over the full range of x. I kept the two regions defined by the solution separate so you can see what's going on.

  ParametricPlot3D[{
     {x,Max@y[x],x^39*(Max@y[x])^63},
     {x,Min@y[x],x^39*(Min@y[x])^63}
     }
    ,{x,-Sqrt[2],Sqrt[2]},PlotRange->All,BoxRatios->1]

Which gives:

enter image description here

$\endgroup$
3
  • 2
    $\begingroup$ You probably want to use Set rather than SetDelayed to avoid evaluating Solve repeatedly. +1 nevertheless. $\endgroup$
    – Mr.Wizard
    Jun 1, 2015 at 22:29
  • 1
    $\begingroup$ Constructing a trigonometric parametrization of the ellipse ought to make for a neater plot. :) $\endgroup$ Jun 2, 2015 at 12:44
  • $\begingroup$ Or ParametricPlot3D[Evaluate[Thread[{x, y[x], x^39*y[x]^63}]], {x, -Sqrt[2], Sqrt[2]}, PlotRange -> All, BoxRatios -> 1] $\endgroup$
    – Bob Hanlon
    Nov 4, 2015 at 19:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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