In [1]:
import numpy as np;
import matplotlib.pyplot as plt;
plt.rcParams.update({"text.usetex":True});
%config InlineBackend.figure_format = "svg"
from ipywidgets import interactive
In [2]:
def analytical(x, ep):
    alpha = (ep**2 + 1)**0.5; 
    B = np.exp(ep)/(np.exp(-alpha) - np.exp(alpha)); A = -B;
    y = np.exp(-ep*x)*(A*np.exp(alpha*x) + B*np.exp(-alpha*x));
    return y

ep = 0.3; 
x = np.linspace(0,1,20); y = analytical(x, ep);
y0 = np.sinh(x)/np.sinh(1);
y1 = (1-x)*np.sinh(x)/np.sinh(1);
plt.plot(x, y, 'r',label="analytical");
plt.plot(x, y0,'--k' ,label="$y_0$");
plt.plot(x, y0+ep*y1, '-.k', label="$y_0 + \epsilon y_1$")
plt.legend();
2021-02-02T21:39:12.884457 image/svg+xml Matplotlib v3.3.3, https://matplotlib.org/
In [ ]: