import numpy as np;
import matplotlib.pyplot as plt;
plt.rcParams.update({"text.usetex":True});
%config InlineBackend.figure_format = "svg"
from ipywidgets import interactive
x_e = np.linspace(0,2);
C1 = np.exp(-4)/(1+np.exp(-4)); C2 = C1*np.exp(4);
f_e = C1*np.exp(x_e) + C2*np.exp(-x_e);
plt.plot(x_e, f_e); plt.xlabel("$x$"); plt.ylabel("f(x)");
from scipy.integrate import solve_bvp
def fun(x, y):
return [y[1], y[0]]
def bc(ya, yb):
return [ya[0]-1, yb[1]-0]
xd = np.linspace(0, 2, 10);
ya = np.zeros((2, xd.size));
res = solve_bvp(fun, bc, xd, ya);
xi = np.linspace(np.min(xd), np.max(xd), 1000);
yi = res.sol(xi)[0]
yid = res.sol(xi)[1]
plt.plot(xi, yi, label='f(x)');
plt.plot(xi, yid, label="f'(x)"); plt.legend(); plt.axhline(0)
<matplotlib.lines.Line2D at 0x1afc8ce2ca0>
def fun(x, y):
return [y[1], 2*y[0]-2*y[1]-3]
def bc(ya, yb):
return [ya[0]-1, yb[0]+2]
xd = np.linspace(0, 2, 10);
ya = np.zeros((2, xd.size));
res = solve_bvp(fun, bc, xd, ya);
xi = np.linspace(np.min(xd), np.max(xd), 1000);
yi = res.sol(xi)[0]
yid = res.sol(xi)[1]
plt.plot(xi, yi, label='f(x)');
plt.plot(xi, yid, label="f'(x)"); plt.legend();