Fast numerical plot command that always works?
I typically encounter expressions of the type
C = -I*sqrt(pi)*x*e^(-1/4*x^2)
Abs = abs(C)
Sage's built-in plot commands fails:
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'
We can evaluate the expression numerically:
X = map(lambda 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 looks like a dirty workaround. Should I use numpy arrays and fast_callable? Or use fast_callable() without numpy?
Here is an example worksheet.
Can you give a complete example (e.g., give us a C function) illustrating the problem? I'm sure we'll be able to help you better then. LIkely, using fast_callable will solve your issue.
@Jason Grout, I update the question with an example and a link to a public worksheet. In this simple example, simplify() would solve the issue, but on more sophisticated expressions simplify will fail.