<jupyter_start><jupyter_text>Given two functions:$$F_{1}(\text{x}) = \cos(t)$$$$F_{2}(\text{x}) = e^{t}$$<jupyter_code>def func1(t):
    return np.cos(t)

def func2(t):
    return np.exp(t)<jupyter_output><empty_output><jupyter_text>Evaluating the derivative of $\cos\left(t\right)$<jupyter_code>vals = []
h_vals = np.linspace(np.finfo(float).eps, 1, 1000)
t_vals = [0.1, 1, 100]

plt.figure(dpi=100)
for i in t_vals:
    vals = []
    errors = []
    true_val = -np.sin(i)
    for h in h_vals:
        val = ForwardDiff(function=func1, t=i, h=h)
        vals.append(val)
        errors.append(abs((val - true_val) / true_val))
    plt.loglog(h_vals, errors, label=f'$t = {i}$')
    plt.legend(loc='best')


plt.title(r'log-log Graph for $\varepsilon$ vs. $h$ using the Forward-Difference method')
plt.xlabel('$h$')
plt.ylabel('$\epsilon$')
plt.show()<jupyter_output><empty_output><jupyter_text>Evaluating the derivative of $e^x$<jupyter_code>vals = []
h_vals = np.linspace(np.finfo(float).eps, 1, 1000)
t_vals = [0.1, 1, 100]

plt.figure(dpi=100)
for i in t_vals:
    vals = []
    errors = []
    true_val = np.exp(i)
    for h in h_vals:
        val = ForwardDiff(function=func2, t=i, h=h)
        vals.append(val)
        errors.append(abs((val - true_val) / true_val))
    plt.loglog(h_vals, errors, label=f'$t = {i}$')
    plt.legend(loc='best')

plt.title(r'log-log Graph for $\varepsilon$ vs. $h$ using the Forward-Difference method')
plt.xlabel('$h$')
plt.ylabel('$\epsilon$')
plt.show()<jupyter_output><empty_output><jupyter_text>Evaluating the derivative of $\cos\left(t\right)$<jupyter_code>vals = []
h_vals = np.linspace(np.finfo(float).eps, 1, 1000)
t_vals = [0.1, 1, 100]

plt.figure(dpi=100)
for i in t_vals:
    vals = []
    errors = []
    true_val = -np.sin(i)
    for h in h_vals:
        val = CentralDiff(function=func1, t=i, h=h)
        vals.append(val)
        errors.append(abs((val - true_val) / true_val))
    plt.loglog(h_vals, errors, label=f'$t = {i}$')
    plt.legend(loc='best')

plt.title(r'log-log Graph for $\varepsilon$ vs. $h$ using the Central-Difference method')
plt.xlabel('$h$')
plt.ylabel('$\epsilon$')
plt.show()<jupyter_output><empty_output><jupyter_text>Evaluating the derivative of $e^x$<jupyter_code>vals = []
h_vals = np.linspace(np.finfo(float).eps, 1, 1000)
t_vals = [0.1, 1, 100]

plt.figure(dpi=100)
for i in t_vals:
    vals = []
    errors = []
    true_val = np.exp(i)
    for h in h_vals:
        val = CentralDiff(function=func2, t=i, h=h)
        vals.append(val)
        errors.append(abs((val - true_val) / true_val))
    plt.loglog(h_vals, errors, label=f'$t = {i}$')
    plt.legend(loc='best')

plt.title('$|\epsilon|$ vs $h$ on a logarithmic scale using\nthe Central-Difference method')
plt.xlabel('Step size $h$')
plt.ylabel('Relative error $\epsilon$')
plt.show()<jupyter_output><empty_output><jupyter_text>Evaluating the derivative of $\cos\left(t\right)$<jupyter_code>vals = []
h_vals = np.linspace(np.finfo(float).eps, 1, 1000)
t_vals = [0.1, 1, 100]

plt.figure(dpi=100) 
for i in t_vals:
    vals = []
    errors = []
    true_val = -np.sin(i)
    for h in h_vals:
        val = ExtrapolatedDiff(function=func1, t=i, h=h)
        vals.append(val)
        errors.append(abs((val - true_val) / true_val))
    plt.loglog(h_vals, errors, label=f'$t = {i}$')
    plt.legend(loc='best')

plt.title(r'log-log Graph for $\varepsilon$ vs. $h$ using the Extrapolated Difference method')
plt.xlabel('$h$')
plt.ylabel('$\epsilon$')
plt.show()<jupyter_output><empty_output><jupyter_text>Evaluating the derivative of $e^x$<jupyter_code>vals = []
h_vals = np.linspace(np.finfo(float).eps, 1, 1000)
t_vals = [0.1, 1, 100]

plt.figure(dpi=100) 
for i in t_vals:
    vals = []
    errors = []
    true_val = np.exp(i)
    for h in h_vals:
        val = ExtrapolatedDiff(function=func2, t=i, h=h)
        vals.append(val)
        errors.append(abs((val - true_val) / true_val))
    plt.loglog(h_vals, errors, label=f'$t = {i}$')
    plt.legend(loc='best')
    
plt.title(r'log-log Graph for $\varepsilon$ vs. $h$ using the Extrapolated Difference method')
plt.xlabel('$h$')
plt.ylabel('$\epsilon$')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18201335877862596, 'fraction_numerical': 0.022423664122137404, 'mean_word_length': 3.875581395348837, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '409339', 'license': 'MIT', 'n_tokens_mistral': 1829, 'n_tokens_neox': 1699, 'n_words': 324, 'path': 'Numerical Method Codes/Exercise on Numerical Derivative - Medrano.ipynb', 'repo_name': 'lindleezy/Numerical-Methods', 'size': '4192'}