<jupyter_start><jupyter_text>Sea $f(x)=e^x$<jupyter_code>def f(x):
    z = np.cos(x) + np.sin(3*x) + np.cos(np.sqrt(x)) + np.cos(18*x)
    return z
f = lambda x: np.exp(x)<jupyter_output><empty_output><jupyter_text>y una partición regular en el intervalo $[0, 1]$ donde se construye el polinomio interpolante de orden $n$, $P_n(x)$.     Interpolación de Newton con N puntos:<jupyter_code>N = 30
xd = np.linspace(2, 10, N)
yd = f(xd)
xi = np.linspace(min(xd), max(xd), 200)
ym = f(xi)<jupyter_output><empty_output><jupyter_text>_______<jupyter_code>yl = it.interp_newton(xi, xd, yd)
fig = plt.figure(figsize=(12, 6))
ax = fig.add_subplot()
ax.plot(xi, yl, linewidth=1.4, linestyle='-', color='orchid', 
        label='lagrange')
ax.plot(xd, yd, marker='o', linestyle='None', color='navy', markersize=5)
ax.grid()
ax.legend()
fig = plt.figure(figsize=(12, 6))
ax = fig.add_subplot()

ax.plot(xi, yl-ym, linewidth=3, color='indigo')

ax.plot(xd, [0]*len(xd), marker='o', linestyle='None', color='navy',
        markersize=8, mfc='white', mec='indigo', mew=2)
ax.set_ylabel('ERROR')
ax.set_xlabel('x')
ax.grid()<jupyter_output><empty_output><jupyter_text>Veamos juntos los errores para diferentes N<jupyter_code>fig, axs = plt.subplots(5, 4, figsize=[15, 18])

for N, ax in zip(range(6, 66, 3), axs.flat):
    xd = np.linspace(2, 10, N)
    yd = f(xd)
    
    xi = np.linspace(min(xd), max(xd), 200)
    ym = f(xi)
    
    ylgg = it.interp_lagrange(xi, xd, yd)
    mx = max(ylgg-ym)
    
    ylin = np.interp(xi, xd, yd)
    
    spline = interp1d(xd, yd, kind='cubic')
    ysp3 = spline(xi)
    
    #ax.plot(xi, ylgg-ym, linewidth=2, color='cornflowerblue', label='lagrange')
    ax.plot(xi, ylin-ym, linewidth=2, color='peru', label='lineal')
    ax.plot(xi, ysp3-ym, linewidth=2, color='mediumaquamarine', linestyle=':', label='cubic spline')
    ax.set_title(f'N={N}; max={mx:5.1e}')
    ax.legend()
    ax.axhline(0, linestyle='--', color='k')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19625695498229642, 'fraction_numerical': 0.025796661608497723, 'mean_word_length': 4.635327635327635, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '668502', 'license': 'MIT', 'n_tokens_mistral': 911, 'n_tokens_neox': 876, 'n_words': 164, 'path': 'codes/clase_14/interp_error_lineal.ipynb', 'repo_name': 'mlares/computacion2020', 'size': '1977'}