Analiza szeregów funkcyjnych¶

In [77]:
import sympy as sp
from IPython.display import Markdown, display

n = sp.symbols('n', integer=True)
x = sp.symbols('x')
a_n = ((3*x+1)**n)/2**n

# prezentacja wyników
latex_code = fr"""
\begin{{align*}}
& \Large \text{{Funkcja }} F={sp.latex(a_n)}
\end{{align*}}
"""
display(Markdown(latex_code))

\begin{align*} & \Large \text{Funkcja } F=2^{- n} \left(3 x + 1\right)^{n} \end{align*}

In [78]:
s_n = summation(a_n, (n, 1, oo))
# prezentacja wyników
latex_code = fr"""
\begin{{align*}}
& \Large \text{{Szereg funkcyjny }} S_n={sp.latex(s_n)}
\end{{align*}}
"""
display(Markdown(latex_code))

\begin{align*} & \Large \text{Szereg funkcyjny } S_n=\begin{cases} \frac{\frac{3 x}{2} + \frac{1}{2}}{\frac{1}{2} - \frac{3 x}{2}} & \text{for}\: \left|{\frac{3 x}{2} + \frac{1}{2}}\right| < 1 \\\sum_{n=1}^{\infty} 2^{- n} \left(3 x + 1\right)^{n} & \text{otherwise} \end{cases} \end{align*}

In [79]:
a_n1 = a_n.subs(n, n+1)
# d'Alembert
ratio = sp.Abs(a_n1 / a_n)
L = sp.simplify(ratio)
# Granica
ineq = sp.limit(L, n, sp.oo) < 1
sol = sp.solve(ineq, x)



# prezentacja wyników
latex_code = fr"""
\begin{{align*}}
& \large \text{{Kryterium d’Alemberta (kryterium ilorazowego)}}  \\ 
& \large \lim_{{n \to \infty}}  \dfrac{{a_{{n+1}}}}{{a_n}} \\ \\
& \large a_n={sp.latex(a_n)} \\ \\
& \large a_{{n+1}}={sp.latex(a_n1)} \\ \\
& \large L(x)={sp.latex(L)}<1 \\ \\
& \large \text{{Przedział}} : {sp.latex(sol)} \\ \\
\end{{align*}}
"""


display(Markdown(latex_code))

\begin{align*} & \large \text{Kryterium d’Alemberta (kryterium ilorazowego)} \\ & \large \lim_{n \to \infty} \dfrac{a_{n+1}}{a_n} \\ \\ & \large a_n=2^{- n} \left(3 x + 1\right)^{n} \\ \\ & \large a_{n+1}=2^{- n - 1} \left(3 x + 1\right)^{n + 1} \\ \\ & \large L(x)=\frac{\left|{3 x + 1}\right|}{2}<1 \\ \\ & \large \text{Przedział} : -1 < x \wedge x < \frac{1}{3} \\ \\ \end{align*}

In [80]:
import numpy as np
import matplotlib.pyplot as plt

# Definicja funkcji: suma częściowa szeregu do N wyrazów
def f_series(x_vs, N=50):
    result = []
    for x_v in x_vs:
        r = 0
        for n_v in range(N):
            r += a_n.subs([(x,x_v),(n,n_v)]).evalf()
        result = np.append(result, r)
    return result

# Zakres x w szerszym przedziale, żeby zobaczyć zbieżność i rozbieżność
x_vals = np.linspace(-1.5, 0.5, 400)
y_vals = f_series(x_vals, N=50)

# Wyznaczenie punktów brzegowych 
ss = sp.solveset(ineq, x, domain=sp.S.Reals)
x_left =  ss.start
x_right = ss.end

# Wykres
plt.figure(figsize=(10, 6))
plt.plot(x_vals, y_vals, label='Suma częściowa szeregu (N=50)', color='blue')
plt.axvline(x_left, color='red', linestyle='--', label='x = -1 (brzeg)')
plt.axvline(x_right, color='green', linestyle='--', label='x = 1/3 (brzeg)')
plt.title("Zbieżność szeregu: $\\sum \\frac{(3x+1)^n}{2^n}$")
plt.xlabel("x")
plt.ylabel("Suma częściowa")
plt.grid(True)
plt.legend()
plt.ylim(-10, 50)
plt.show()
No description has been provided for this image
In [81]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from IPython.display import HTML


# Przygotowanie danych
x_vals = np.linspace(-1.5, 0.5, 400)
N_max = 50

# Wykres
fig, ax = plt.subplots(figsize=(10, 6))
line, = ax.plot([], [], color='blue', label='Suma częściowa')
ax.axvline(x_left, color='red', linestyle='--', label='x = -1 (brzeg)')
ax.axvline(x_right, color='green', linestyle='--', label='x = 1/3 (brzeg)')
ax.set_xlim(-1.5, 0.5)
ax.set_ylim(-10, 50)
ax.set_title("Animacja: Zbieżność szeregu $\\sum \\frac{(3x+1)^n}{2^n}$")
ax.set_xlabel("x")
ax.set_ylabel("Suma częściowa")
ax.grid(True)
ax.legend()

# Inicjalizacja
def init():
    line.set_data([], [])
    return line,

# Aktualizacja
def update(n):
    y_vals = f_series(x_vals, n+1)
    line.set_data(x_vals, y_vals)
    ax.set_title(f"Suma częściowa dla N = {n+1}")
    return line,

# Animacja
ani = animation.FuncAnimation(fig, update, frames=N_max, init_func=init, blit=True, interval=100)

# Wyświetlenie animacji w HTML
HTML(ani.to_jshtml())
Out[81]:
No description has been provided for this image
No description has been provided for this image