Sharedfirst_steps / InClass / The Limit of Functions.sagewsOpen in CoCalc
from sage.symbolic.relation import solve_ineq
@interact
def _(error=input_box(1,label='If we want the distance between $x^2+2x+2$ and $1$ smaller than ')):
    f=x^2+2*x+2
    background=plot(x^2+2*x+2,-2.5,0.5,thickness=3)
    solution=(x^2+2*x+1-error).roots(ring=RR)
    Line0=plot(1,-2.5,0.5,thickness=1.5,linestyle='--')
    Line1=plot(1+error,-2.5,0.5,thickness=1.5,linestyle='--')
    Line2=line([(solution[0][0],0),(solution[0][0],3)],linestyle='--',thickness=1.5)
    Line3=line([(solution[1][0],0),(solution[1][0],3)],linestyle='--',thickness=1.5)
    Line4=line([(0.5,1),(0.5,1+error)],marker='^')
    background+=Line0
    background+=Line1
    background+=Line2
    background+=Line3
    background+=Line4
    graphs=point([(solution[i][0],0) for i in range(2)],size=100,color='red')+background
    graphs.show(figsize=10)
Interact: please open in CoCalc
background=plot(x^2,0,2,thickness=3,aspect_ratio=1/2)
times=[1+1/n for n in range(1,121)]
films=[point([(t,t^2),(t,0),(0,t^2)],color='red',size=100)+line([(t,t^2),(0,t^2)],linestyle="--",thickness=1.5)+line([(t,t^2),(t,0)],thickness=1.5,linestyle="--")+background for t in times]
a=animate(films,xmax=2,xmin=0,ymax=4,ymin=-0.1,figsize=15)
show(a)
Error in lines 5-5 Traceback (most recent call last): File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1013, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_salvus.py", line 2678, in show s = show0(objs, combine_all=True) File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_salvus.py", line 2639, in show0 b = show0(a) File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_salvus.py", line 2608, in show0 show_animation(obj, **kwds) File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_salvus.py", line 2402, in show_animation obj.ffmpeg(t, delay=delay, **kwds) File "/ext/sage/sage-8.1/local/lib/python2.7/site-packages/sage/plot/animate.py", line 930, in ffmpeg pngdir = self.png() File "/ext/sage/sage-8.1/local/lib/python2.7/site-packages/sage/plot/animate.py", line 469, in png save_image(filename, **self._kwds) File "/ext/sage/sage-8.1/local/lib/python2.7/site-packages/sage/plot/graphics.py", line 3025, in save_image self.save(filename, *args, **kwds) File "/ext/sage/sage-8.1/local/lib/python2.7/site-packages/sage/misc/decorators.py", line 483, in wrapper return func(*args, **kwds) File "/ext/sage/sage-8.1/local/lib/python2.7/site-packages/sage/plot/graphics.py", line 3189, in save figure.tight_layout() File "/ext/sage/sage-8.1/local/lib/python2.7/site-packages/matplotlib/figure.py", line 1754, in tight_layout rect=rect) File "/ext/sage/sage-8.1/local/lib/python2.7/site-packages/matplotlib/tight_layout.py", line 349, in get_tight_layout_figure pad=pad, h_pad=h_pad, w_pad=w_pad) File "/ext/sage/sage-8.1/local/lib/python2.7/site-packages/matplotlib/tight_layout.py", line 126, in auto_adjust_subplotpars tight_bbox_raw = union([ax.get_tightbbox(renderer) for ax in subplots]) File "/ext/sage/sage-8.1/local/lib/python2.7/site-packages/matplotlib/axes/_base.py", line 3683, in get_tightbbox bb_yaxis = self.yaxis.get_tightbbox(renderer) File "/ext/sage/sage-8.1/local/lib/python2.7/site-packages/matplotlib/axis.py", line 1073, in get_tightbbox ticks_to_draw = self._update_ticks(renderer) File "/ext/sage/sage-8.1/local/lib/python2.7/site-packages/matplotlib/axis.py", line 949, in _update_ticks tick_tups = [t for t in self.iter_ticks()] File "/ext/sage/sage-8.1/local/lib/python2.7/site-packages/matplotlib/axis.py", line 899, in iter_ticks minorTicks = self.get_minor_ticks(len(minorLocs)) File "/ext/sage/sage-8.1/local/lib/python2.7/site-packages/matplotlib/axis.py", line 1318, in get_minor_ticks tick = self._get_tick(major=False) File "/ext/sage/sage-8.1/local/lib/python2.7/site-packages/matplotlib/axis.py", line 2000, in _get_tick return YTick(self.axes, 0, '', major=major, **tick_kw) File "/ext/sage/sage-8.1/local/lib/python2.7/site-packages/matplotlib/axis.py", line 150, in __init__ self.tick1line = self._get_tick1line() File "/ext/sage/sage-8.1/local/lib/python2.7/site-packages/matplotlib/axis.py", line 538, in _get_tick1line zorder=self._zorder) File "/ext/sage/sage-8.1/local/lib/python2.7/site-packages/matplotlib/lines.py", line 338, in __init__ self._marker = MarkerStyle() File "/ext/sage/sage-8.1/local/lib/python2.7/site-packages/matplotlib/markers.py", line 172, in __init__ self.set_fillstyle(fillstyle) File "/ext/sage/sage-8.1/local/lib/python2.7/site-packages/matplotlib/markers.py", line 222, in set_fillstyle self._recache() File "/ext/sage/sage-8.1/local/lib/python2.7/site-packages/matplotlib/markers.py", line 186, in _recache self._transform = IdentityTransform() File "/ext/sage/sage-8.1/local/lib/python2.7/site-packages/matplotlib/transforms.py", line 1641, in __init__ Transform.__init__(self, *args, **kwargs) File "/ext/sage/sage-8.1/local/lib/python2.7/site-packages/matplotlib/transforms.py", line 98, in __init__ self._parents = WeakValueDictionary() File "/ext/sage/sage-8.1/local/lib/python2.7/weakref.py", line 56, in __init__ def remove(wr, selfref=ref(self), _atomic_removal=_remove_dead_weakref): File "src/cysignals/signals.pyx", line 251, in cysignals.signals.python_check_interrupt File "src/cysignals/signals.pyx", line 94, in cysignals.signals.sig_raise_exception KeyboardInterrupt
background=plot(x^2*(x-1)/(x-1),0,2,thickness=3,aspect_ratio=1/2)
pt = point([(1,0),(1, 1)], rgbcolor='white', pointsize=100, faceted=True)
background+=pt
times=[1+1/n for n in range(1,121)]
films=[point([(t,t^2),(t,0),(0,t^2)],color='red',size=100)+line([(t,t^2),(0,t^2)],linestyle="--",thickness=1.5)+line([(t,t^2),(t,0)],linestyle="--",thickness=1.5)+background for t in times]
a=animate(films,xmax=2,xmin=0,ymax=4,ymin=-0.1,figsize=15)
show(a)

background=plot(1/t,0,1,ymin=0,ymax=(100),xmin=0,xmax=1,aspect_ratio=1/(100),linestyle='--')
films=[background+point([(1/x,x),(1/x,0)],color='red', size=100)+line([(1/x,x),(1/x,0)],linestyle='--',thickness=1.5) for x in range(1,101)]
a=animate(films)
a.show()