5
$\begingroup$

I want to plot some function . The code is given below.

f = 10000000;
v0 = 8.7;
T = 1*(1/f);
v[t] = v0*Sin[2*\[Pi]*f*t];
Plot[%, {t, 0, T} ]

Now the plot will make a plot of my function v[t] from 0 to T. What is the step size in this plotting ? How to change this step size ? What is by default step size? Thanks

$\endgroup$
2
  • 1
    $\begingroup$ To obtain fixed stepsize, stick to ListPlot[Table[{t, %}, {t, 0, T, T/(steps+1)}]]. Plot has options: PlotPoints and MaxRecursions to control the mesh $\endgroup$
    – Coolwater
    May 3, 2015 at 7:14
  • 1
    $\begingroup$ "How to change this step size ? What is by default step size?" - that you ask this means you are not aware that Mathematica does something called adaptive sampling when it plots functions. Crudely stated, it means that Mathematica starts with an initial set of points (controlled by the PlotPoints option) and then keeps on refining it until the kinkiest parts of what it's plotting have been sufficiently sampled (controlled by MaxRecursion and the now-hidden option MaxBend). $\endgroup$ May 4, 2015 at 4:11

1 Answer 1

6
$\begingroup$

You can use Plot with option combination PlotPoints and MaxRecursion (as mentioned by @coolwater in the comments), or DiscretePlot:

ClearAll[v]
ff = 10000000; v0 = 8.7; T = 1*(1/ff);
v[t_] := v0*Sin[2*\[Pi]*ff*t];

plt1 = Plot[v[t], {t, 0, T}, PlotStyle -> Blue];
plt2 = Plot[v[t], {t, 0, T}, PlotPoints -> 10, MaxRecursion -> 0, 
   PlotStyle -> Opacity[1, Red]];
plt3 = DiscretePlot[{v[t], v[t]}, {t, 0, T, T/9},
   PlotStyle -> Directive[Opacity[.5, Orange], Thickness[.01]], 
   Joined -> True, ImageSize -> 400, Filling -> None];

Legended[Show[plt1, plt3, plt2, ImageSize -> 500], 
 LineLegend[{Blue, Red, Orange}, Style[#, 20, "Palette"]&/@ {"Plot[v[t], {t, 0, T}]", 
    "Plot[v[t], {t, 0, T}, \nPlotPoints -> 10, MaxRecursion -> 0]", 
    "DiscretePlot[{v[t], v[t]}, {t, 0, T, T/9}]"}]]

Mathematica graphics

$\endgroup$

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.