3
$\begingroup$

When you tell Wolfram|Alpha to plot something, it automatically figures out a reasonable domain to plot it over. When I try something like

Plot x^2 + y^2 = 1000

it automatically translates that to

ContourPlot[x^2 + y^2 == 1000, {x, -40, 40}, {y, -40, 40}]

and gives me back a nice circle.

Now this isn't even a function, but I'd be pretty happy even if this could be done just for functions, or even only relatively simple ones at that.

I'm pretty new to Mathematica, and for the life of me, I can't figure out how to do this with Mathematica. I just want it to plot the function and figure out the range itself! It drives me nuts to have to say

Plot[f[x], {x, -8, 8}]

when I have no idea what f will look like.

How can I have Mathematica figure out a reasonable domain by itself? I don't need it to be perfect, just something that isn't totally unreasonable (e.g. a blank plot). It can't be that hard for a system that can symbolically solve differential equations.

$\endgroup$
  • 2
    $\begingroup$ An interesting question but could you provide additional examples? How are more complicated functions handled? $\endgroup$ – Mr.Wizard Jul 7 '15 at 6:40
  • $\begingroup$ @Mr.Wizard: I'm not sure if I should be reading between the lines of your comment or if I'm understanding what you're asking me. If you literally just want me to run more examples, I'd be happy to, just tell me what function you want to see the plot for because I have no idea what you're looking for. But if this is just a subtle way of suggesting that it's unreasonable to expect such a feature to exist because it can't handle arbitrarily complex functions... well yes, I realize nothing in the world can handle arbitrarily complex tasks, but so what? $\endgroup$ – Mehrdad Jul 7 '15 at 6:56
  • $\begingroup$ No reading between the lines needed. I merely would like to see how MATLAB is handling some nontrivial examples as a reference for attempting to emulate its behavior. Also I would like to know what should be done for functions that cannot be symbolically analyzed. Should we evaluate an arbitrary range of x values and then attempt narrow the plot to an "interesting" part of the result? $\endgroup$ – Mr.Wizard Jul 7 '15 at 7:03
  • 2
    $\begingroup$ For the updated question: consider building a function around RegionPlot of an ImplicitRegion form of your equation. At least for simple cases, RegionPlot is capable of reasoning the bounds of a geometric region (v10 functionality). An example: RegionPlot[ImplicitRegion[x^2 + y^2 == 1000, {x, y}]] $\endgroup$ – kirma Jul 7 '15 at 7:41
  • 1
    $\begingroup$ @kirma: Cool! Feel free to post it as an answer. $\endgroup$ – Mehrdad Jul 7 '15 at 7:48
5
$\begingroup$

se.mathworks.com/help/matlab/ref/ezplot.html:

ezplot(fun) plots the expression fun(x) over the default domain -2π < x < 2π, where fun(x) is an explicit function of only x.

(... and pretty much the same for other variations.) That wasn't actually at all as fancy as I expected!

Thus the simplest case:

ClearAll[ezplot];

ezplot[expr_, rest___] := Plot[expr, {x, -2 Pi, 2 Pi}, rest];
SetAttributes[ezplot, HoldAll]; (* just to act like Plot *)

EDIT: Now my answer looks strange... why? Because OP extensively edited the question while I was answering it.

Starting point for the edited question:

ClearAll[ezregion];

ezregion[expr_, rest___] := RegionPlot[ImplicitRegion[expr, {x, y}], rest];
SetAttributes[ezregion, HoldAll];

Now you can perform automatic 2D region plot for expressions involving x and y:

ezregion[x^2 + y^2 == 1000]
$\endgroup$
4
$\begingroup$

Try typing the equal sign first (=), and then, in words, "plot x^2".

EDIT:

You can read more about the Free-Form input here.

$\endgroup$
  • $\begingroup$ So you're saying I need internet access in order to get this functionality? It takes so long for it to evaluate... at that point I'm just using Wolfram Alpha... or I might as well just give up and use MATLAB. $\endgroup$ – Mehrdad Jul 7 '15 at 6:46
  • $\begingroup$ I'm afraid so... $\endgroup$ – user1337 Jul 7 '15 at 6: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.