Analiza szeregów numerycznych¶

In [2]:
from sympy import summation, symbols, limit, oo, factorial
import sympy as sp
from IPython.display import Markdown, display
n = symbols('n', integer=True)
a_n = factorial(2*n)/(n**(2*n)+2**n)

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

\begin{align*} & \Large \text{Ciąg liczbowy } a_n=\frac{\left(2 n\right)!}{2^{n} + n^{2 n}} \end{align*}

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

\begin{align*} & \Large \text{Szereg liczbowy } S_n=\sum_{n=1}^{\infty} \frac{\left(2 n\right)!}{2^{n} + n^{2 n}} \end{align*}

In [4]:
a_n1 = a_n.subs(n, n+1)
ratio = a_n1 / a_n

# Obliczamy granicę tego ilorazu dla n -> ∞
limit_expr = sp.limit(ratio, n, sp.oo)
limit_val = limit_expr.evalf(3)

if limit_val < 1:
    wynik = "< 1; Szereg jest zbieżny wg kryterium d'Alemberta."
else:
    wynik = "> 1; Szereg kjest rozbieżny wg kryterium d'Alemberta."

# 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 \lim_{{n \to \infty}}{sp.latex(ratio)}={sp.latex(limit_expr)}\approx{sp.latex(limit_val)} \\ \\
& \large \text{{{wynik}}}  \\ 
\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=\frac{\left(2 n\right)!}{2^{n} + n^{2 n}} \\ \\ & \large a_{n+1}=\frac{\left(2 n + 2\right)!}{2^{n + 1} + \left(n + 1\right)^{2 n + 2}} \\ \\ & \large \lim_{n \to \infty}\frac{\left(2^{n} + n^{2 n}\right) \left(2 n + 2\right)!}{\left(2^{n + 1} + \left(n + 1\right)^{2 n + 2}\right) \left(2 n\right)!}=\frac{4}{e^{2}}\approx0.541 \\ \\ & \large \text{< 1; Szereg jest zbieżny wg kryterium d'Alemberta.} \\ \end{align*}

In [5]:
import matplotlib.pyplot as plt
from math import factorial
import numpy as np

def fa_n(n_v):
    #return factorial(2 * n) / (n**(2 * n) + 2**n)
    return a_n.subs(n, n_v).evalf()

# Zakres n
N = 15
ns = np.arange(1, N + 1)
an_vals = [fa_n(n) for n in ns]

# Sumy częściowe
partial_sums = np.cumsum(an_vals)

# Wykres sum częściowych
plt.figure(figsize=(10, 6))
#plt.plot(ns, partial_sums, 'o-', label='Suma częściowa $S_k$')
l = sp.latex(s_n);
plt.plot(ns, partial_sums, 'o-', label=f'Suma częściowa ${l}$')
plt.xlabel('n')
plt.ylabel('Suma $S_n$')
plt.title('Graficzna prezentacja sum częściowych szeregu')
plt.grid(True)
plt.legend()
plt.show()
No description has been provided for this image