Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Function returning graphic object

I have a function that I want to plot, to be exact that function is like:

dn(k, n, theta, y) = ...

I want to plot it for k, with all other parameters fixed. What seemed the most logic to me was to have a function returning it:

plot_dn(n, theta, y) = plot(dn(k, n, theta, y), (k, 0, 1))

# Idea: simplify plotting by just calling (for example):
plot_dn(100, 0.4, 0.5)
plot_dn(100, 0.6, 0.5)
plot_dn(100, 0.6, 0.8)

plot_dn should be a function creating a graphic object, not a graphic object (ie, plot should be called only when plot_dn is). Problem is that this throw a really large callstack (side point: a callstack is not an error report, sagemath should really have proper error reporting), which ends up with ValueError: Variable 'k' not found.

If I put the function in a list, the error changes:

plot_dn(n, theta, y) = plot([dn(k, n, theta, y)], (k, 0, 1))
# Error is: TypeError: unable to simplify to float approximation

How can I make it work ?