3

Consider the following code:

fun[x_] := x^2;
Plot[fun[x], {x, -4, 4}]

which simply plots a parabola for the range of -4 to 4. I don't know how many points between -4 and 4 Mathematica uses to plot the function? My question is how can I control this number? In fact I have a complicated function which its evaluation takes a long time. On the other hand I need to plot it in range of 0 to 4 to see its shape. When I try Plot command in the range of {0,4} it takes a very very long time to get the curve (it has never finished), so I want to reduce number of points. I took a look on the options of Plot command but I didn't find my desire one. Any idea?

Wisdom
  • 1,258
  • 7
  • 13

1 Answers1

4

You can use the options PlotPoints and MaxRecursion. For example

fun[x_] := x^2;
Plot[fun[x], {x, -4, 4}, PlotPoints -> 5, MaxRecursion -> 0]

gives

enter image description here

Roderic
  • 346
  • 1
  • 5
  • PlotPoints is the number of points? – Wisdom Dec 03 '20 at 15:13
  • PlotPoints is the number of initial sampling points. MaxRecursion the number of times the sampling is iterated. As an example, the options PlotPoints -> 5, MaxRecursion -> 0 and PlotPoints -> 2, MaxRecursion -> 2 give the same answer. – Roderic Dec 03 '20 at 15:16