Ask Your Question
1

Plot ratio of Bessel functions

asked 2020-11-22 23:49:14 +0100

wmaddox gravatar image

updated 2020-11-25 19:56:19 +0100

slelievre gravatar image

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 flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2020-11-23 00:52:48 +0100

slelievre gravatar image

updated 2020-11-23 00:56:35 +0100

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
edit flag offensive delete link more

Comments

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.

wmaddox gravatar imagewmaddox ( 2020-11-23 10:18:50 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2020-11-22 23:49:14 +0100

Seen: 411 times

Last updated: Nov 25 '20