My first problem is simila to one I already
signaled : contrary to plot, plot3d doesn't plots surfaces when even one point has no nice, defined value.
Case in point (yes, I'm aware of
complex_plot, but I needed a 3D model, for pedagogical reasons...) :
sage: var("x,y")
(x, y)
sage: plot3d(abs(gamma(x+I*y)),(x,-2.5,2.5),(y,-2.5,2.5))[ Looong stack trace : see enclosed log. Snip... ]
TypeError: unable to coerce to a real number Indeed : my grid probably contains a non-positive integer. Let's write a function where such exceptions can be catched and givet "flag" values, that could be eliminated later. First try :
sage: def toto(x,y,cl=10.0):
....: r=(CDF(RDF(x)+I*RDF(y)))
....: return r
....: Test it on a small matrix :
argums=matrix([[toto((x-5)/10,(y-5)/10) for y in range(11)] for x in range
....: (11)],ring=CDF)
sage: argums[4:7,4:7]
[-0.1 - 0.1*I -0.1 -0.1 + 0.1*I]
[ -0.1*I 0.0 0.1*I]
[ 0.1 - 0.1*I 0.1 0.1 + 0.1*I]My grid indeeds contains 0.
sage: vals=matrix(map(lambda t:map(lambda u:gamma(u), t), argums))
sage: vals[4:7,4:7]
[A number less than infinity A number less than infinity A number less than infinity]
[A number less than infinity Infinity A number less than infinity]
[A number less than infinity A number less than infinity A number less than infinity]WTF ?
sage: vals.parent()
Full MatrixSpace of 11 by 11 dense matrices over The Unsigned Infinity RingAaarghh.. All my values have been coerced to a two-element rng : infinite and non-infinite. Something like that must happen in the internals of
plot3d. (No, I didn't yet looked at them...).
Trying to coerce the results to CDF fails (see attached log).
Second problem : I can't for the life of me think of a way to catch this problem in the function generating the value. One cannot test for infinity. One possible way would be to test for
(1/r).is_zero(), but this is bound to fail on functions that might have zeroes...
A possible workaround would be to collect the values not in a matrix, but in a list of lists (no coercion to a common ring), and post-process it later (in an hypothetical new version of plot3d, which would be able to omit "holes" in the function...).
Other possible workaround : coerce such infinite values to something in CDF marking infinite values (this must exist, since CDF has an
is_finte() method...). But touching to corections is tricky...
Anyway, all these workarounds do not solve the current impossibility to plot surfaces not entirely defined...
Any ideas ?
--
Emmanuel Charpentier