<jupyter_start><jupyter_text>Interactive partial sums of sineZoufiné Lauer-Baré<jupyter_code>class plot():
    
    def __init__(self, preWidgetN):
        
        self.N = preWidgetN
        
        x,y,n ,k = sym.symbols('x, y,n,k', real=True)
        X=np.linspace(0, 10, 100)
        
        f = sym.Sum((-1)**k*(x**(2*k+1))/(sym.factorial(2*k+1)),(k,0, n))
        #f = sym.Sum((-1)**k*(x**(2*k))/(sym.factorial(2*k)),(k,0, n))
        #print(sym.latex(f))
        f = f.subs(n, self.N.value)
        f = sym.lambdify(x, f)
        self.trace1 = go.Scatter(x=X, y=np.sin(X),
                            mode='lines+markers',
                            name='sin'
                               )
        self.trace2 = go.Scatter(x=X, y=f(X),
                            mode='lines',
                            name=r'$\sum_{k=0}^{%s} \frac{\left(-1\right)^{k} x^{2 k + 1}}{\left(2 k + 1\right)!}$' %(self.N.value)
                               )
        
        layout = go.Layout(template='plotly_dark', title="Partial sums of sine")

        self.fig = go.FigureWidget(data=[self.trace1, self.trace2], 
                                   layout = layout,
                                   layout_yaxis_range=[-3 , 3],
                                  )
        
        #self.fig.update_layout(title="Plot Title",)

    def sineSeries(self, change):

        x,y,n ,k = sym.symbols('x, y,n,k', real=True)
        X=np.linspace(0, 10, 100)
        f = sym.Sum((-1)**k*(x**(2*k+1))/(sym.factorial(2*k+1)),(k,0, n))
        #f = sym.Sum((-1)**k*(x**(2*k))/(sym.factorial(2*k)),(k,0, n))
        f = f.subs(n, self.N.value)
        f = sym.lambdify(x, f)




        with self.fig.batch_update():
            self.fig.data[1].x = X
            self.fig.data[1].y = f(X)
            self.fig.data[1].name = r'$\sum_{k=0}^{%s} \frac{\left(-1\right)^{k} x^{2 k + 1}}{\left(2 k + 1\right)!}$' %(self.N.value)

        return 
    
    def show(self):
        self.N.observe(self.sineSeries, names='value')
        display(self.N, self.fig)
        return
N = widgets.IntSlider(min=0, max=20, step=1, value=0, description='partial sum order')

p = plot(N)

p.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19745801180208805, 'fraction_numerical': 0.026327734906945077, 'mean_word_length': 1.7009803921568627, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '147883', 'license': 'MIT', 'n_tokens_mistral': 864, 'n_tokens_neox': 821, 'n_words': 122, 'path': 'interactive_sinus.ipynb', 'repo_name': 'zolabar/Interactive-Calculus', 'size': '2203'}