Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Fast numerical plot command that always works?

I typically encounter expressions of the type:

E = abs(C)

or

E = C * C.conjugate()

Here, C is a complex expression (function) of one more independent variables x, y, ...

Sage's built-in plot commands sometimes fail to plot E with errors such as "cannot simplify to float approximation".

XList = range(100)
Elist = map(lambda X: real(E.subs(x=X).n()), Xlist)
list_plot(zip(XList, EList))

works, but it can be very slow and looks like a dirty workaround. Should I use numpy arrays and fast_callable? Or use fast_callable() without numpy?

Fast numerical plot command that always works?

I typically encounter expressions of the type:type

E  C = -I*sqrt(pi)*x*e^(-1/4*x^2)
 Abs = abs(C)

or Sage's built-in plot commands fails:

E = C * C.conjugate()
verbose 0 (4101: plot.py, generate_plot_points) WARNING: When plotting,
failed to evaluate function at 200 points.
verbose 0 (4101: plot.py, generate_plot_points) Last error message:
'unable to simplify to float approximation'

Here, C is a complex We can evaluate the expression (function) of one more independent variables x, y, ...

Sage's built-in plot commands sometimes fail to plot E with errors such as "cannot simplify to float approximation".numerically:

XList = range(100)
Elist X = map(lambda X: real(E.subs(x=X).n()), Xlist)
list_plot(zip(XList, EList))
x: x/10, range(-100,100))
Y = map(lambda xx: Abs.subs(x=xx).n(), X)
Yreal = map(real, Y)
Yimag = map(imag, Y)
list_plot(zip(X,Yreal)) + list_plot(zip(X,Yimag),color='red')

This works, but it can be very slow and looks like a dirty workaround. Should I use numpy arrays and fast_callable? Or use fast_callable() without numpy?

Here is an example worksheet.