ROOT Function Plotter

Hey ,
Im plotting this sinc function(sin(x)/x) using TF1 class,
when I plot it for the short range it gives me the accurate result (value 1 at x=0).
but when I plot it for large range it gives me some strange plot, also the value at x=0 is not 1 now
please explain .

TF1 f1(“f1”, “sin(x)/x”,-10,10);
f1.Draw();
for large range
TF1 f1(“f1”, “sin(x)/x”,0,2000);
f1.Draw();


TF1 f1(“f1”, “sin(x)/x”,-1000,2000);
f1.Draw();
__

Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


Use, e.g.:
TF1 f1("f1", "(abs(x) > 1.e-11 ? sin(x) / x : 1.)", 0., 2000.);
Then, e.g.:
f1.SetNpx(10000);

Hi @Subhu18 ,

sin(x)/x is not defined at x==0, but it tends to 1 in the limit in which x tends to 0.

In order to draw the plot, TF1 simply evaluates the function in a few points and then interpolates. With the larger range, the sampling is too coarse and close to x==0 you get a datapoint that corresponds e.g. to x == 1.5 or something like that.

Cheers,
Enrico

P.S.
in other words it’s just an artifact of the visualization done via sampling. If you evaluate the TF1 around x==0 you get the correct behavior, e.g.:

root [1] auto *f = new TF1("f1", "sin(x)/x", -2000, 2000)
(TF1 *) 0x562d34d5ee50
root [2] f->Eval(0.1)
(double) 0.99833417
root [3] f->Eval(0.001)
(double) 0.99999983
1 Like

May I know the reason the whats wrong with my code??

thank you for the clarification sir.