# Plot ratio of Bessel functions

I am new to SageMath and to this page. I'm running this version:

SageMath version 9.2, Release Date: 2020-10-24 Using Python 3.8.5.

I tried to plot the ratio of two functions related to Bessel functions.

First I defined f as the first derivative of bessel_J(1, x) and gas x*bessel_J(1, x):

f(x) = bessel_J(1, x)
g = derivative(f, x)


Then I defined h as their ratio:

h = g / (x*f)


Then, I tried to plot h with:

plot(h, (x, 0, 10))


The result is an empty plot, showing only the x, y axes, and this is not correct.

Am I doing something wrong? Is it possible to plot such a function and, if yes, how?

edit retag close merge delete

Sort by » oldest newest most voted

The plot is not empty. If you look carefully you will see a blue line stuck along the axes.

The function h is a quotient of two functions, and the denominator has zeros on the plotting interval.

This means the function h takes immense values.

Because of this, the scale chosen for y is immense, which is sadly not reflected in the tick labels.

The tick labels, which look like 0.5 to 4.0, are really 0.5e6 to 4.0e6, but for some reason do not display properly.

Check this:

sage: ph = plot(h, (0, 10))

sage: ph.get_minmax_data()
{'xmin': 0.0005025125628140704,
'xmax': 10.0,
'ymin': -102.31864962768964,
'ymax': 3960099.7499999963}


The solution is to show an appropriate view by setting ymin and ymax.

Additionally you can use detect_poles=True to get rid of spurious vertical lines when the function jumps from minus infinity to plus infinity.

Depending on the scale you choose, try something like:

sage: ph = plot(h, (0, 10), detect_poles=True)

sage: ph.show(ymin=-100, ymax=100)
Launched png viewer for Graphics object consisting of 3 graphics primitives

sage: ph.show(ymin=-10, ymax=10)
Launched png viewer for Graphics object consisting of 3 graphics primitives

sage: ph.show(ymin=-1, ymax=1)
Launched png viewer for Graphics object consisting of 3 graphics primitives

more

Thank you! What was confusing me was the scale of the output graph, with the y-axis apparently between 0.0 and 5.0 (no clues about the e6 part in the image). Now it works correctly setting an appropriate ymin and ymax as you suggested.