Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

generate_plot_points fails to evaluate points, while plot image part of expression

Hello,

I solve cubic equation and try to plot imaginary part of its solutions (to find out, at which intervals roots are purely real).

The code is something like this

var('a, b, P, E')

P_sols = solve(a*P + b*P**3 - E, P)

P1 = lambda E_: P_sols[0].rhs().subs({a:-5, b:5, E:E_}).n().imag()
plot(P1, [-10, 10])

Plot function (actually, generate_plot_command) fails to evaluate at points, where image part is nearly zero (range approximately between -2 and 2).

verbose 0 (4190: plot.py, generate_plot_points) WARNING: When plotting,
failed to evaluate function at 39 points.
verbose 0 (4190: plot.py, generate_plot_points) Last error message:
'negative number cannot be raised to a fractional power'

But if I try to evaluate this function directly

P1(0)  # OK
P1(float(0))  # OK

it works OK.

I've found on ask-sage (here), that to create callables it is better to use fast_callable, but I still wonder, why I can call function directly, but plot() function cannot. I've looked into code of generate_plot_points and find there only call line (x, f(x)), so I cannot understand, why it do not work.

I've already solved my practical issue with fast_callable(), but I'm still curious about this behavior.

Thanks.

generate_plot_points fails to evaluate points, while plot image imaginary part of expression

Hello,

I solve cubic equation and try to plot imaginary part of its solutions (to find out, at which intervals roots are purely real).

The code is something like this

var('a, b, P, E')

P_sols = solve(a*P + b*P**3 - E, P)

P1 = lambda E_: P_sols[0].rhs().subs({a:-5, b:5, E:E_}).n().imag()
plot(P1, [-10, 10])

Plot function (actually, generate_plot_command) fails to evaluate at points, where image part is nearly zero (range approximately between -2 and 2).

verbose 0 (4190: plot.py, generate_plot_points) WARNING: When plotting,
failed to evaluate function at 39 points.
verbose 0 (4190: plot.py, generate_plot_points) Last error message:
'negative number cannot be raised to a fractional power'

But if I try to evaluate this function directly

P1(0)  # OK
P1(float(0))  # OK

it works OK.

I've found on ask-sage (here), that to create callables it is better to use fast_callable, but I still wonder, why I can call function directly, but plot() function cannot. I've looked into code of generate_plot_points and find there only call line (x, f(x)), so I cannot understand, why it do not work.

I've already solved my practical issue with fast_callable(), but I'm still curious about this behavior.

Thanks.