
Wow, this is a great animation. Sorry the plotting is so distracting at
the ends!
To narrow down the issue, I executed the following after the code you gave:
sage: endpoints = [v[i][0].xdata[-1] for i in srange(50)]
sage: max(endpoints) - min(endpoints)
0.0039542538407206784
This computes the endpoints for the x-values that are sampled to plot
the graph. That's quite a spread for having the exact same inputs,
which explains the noticable wiggling.
So now the question is: why in the world do we have such different
endpoints?
I might point out that the wiggling is not just at the endpoints of the
graph. The wiggling is throughout the graph; it's just really
noticeable at the endpoints.
Jason
The actual sample points are slightly randomized, so the above
plots may look slightly different each time you draw them.
I assume that this an easy way to get the behavior:
Note that this function does NOT simply sample equally spaced
points between xmin and xmax. Instead it computes equally spaced
points and add small perturbations to them. This reduces the
possibility of, e.g., sampling sin only at multiples of 2pi,
which would yield a very misleading graph.
So, perhaps this is a "feature". But it seems to me that the endpoints,
at least, should be always included (if possible) when graphing a
function, so maybe this is a bug. (Although it is nice to not include
the endpoints when plotting something like sin(1/x).)
But anyway, I think that you should be able to instead do:
f = x*sin(x^2)
v = []
graph = plot(f, [-1, 3], thickness = 1, rgbcolor = (1, 0 ,0))
for i in srange(50):
v.append(graph)
curve = animate(v)
curve.show()
Aha, looking at the help always helps!
plot? has the following:
The actual sample points are slightly randomized, so the above
plots may look slightly different each time you draw them.
Presumably this is to avoid things like sampling the same y-value on a
periodic curve. Unfortunately, it also seems to lead to this wiggling.
The problem in this case is that the randomness was applied to the
beginning and ending points of the interval. A patch is up at
http://trac.sagemath.org/sage_trac/ticket/2236 which fixes this issue.
The patch is just waiting for someone to referee it. Are you
comfortable doing that?
On another note, we still have wiggling in the middle of the graph.
There ought to be options for turning off the randomness and for turning
off the adaptive plotting for situations like your animation. Creating
these options is trac ticket #2237.
Jason
This patch has now been reviewed and merged into the next version of
Sage (due in a few short hours). Your example should look much better then.
Jason
The above code is still preferable, even after the next release, because
there is still some randomness in how interior points are chosen,
leading to some wiggle in the graph. The only thing fixed in this next
release is the endpoints being adjusted randomly.
Not to mention that the above code does the plot calculation only once,
which is faster anyway.
Jason
I've posted a patch here:
http://trac.sagemath.org/sage_trac/ticket/2244
that adds an option
plot(..., randomize=False)
that turns off all randomness in the choice of interior points.
This patch should be applied *after* your (=Jason Grout's) plot
fix. Jason, can you referee this?
>
> Not to mention that the above code does the plot calculation only once,
> which is faster anyway.
>
>
>
> Jason
>
>
> >
>
--
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org