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]:
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)");
2021-02-02T20:37:12.840092 image/svg+xml Matplotlib v3.3.3, https://matplotlib.org/
In [3]:
from scipy.integrate import solve_bvp
In [4]:
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)
Out[4]:
<matplotlib.lines.Line2D at 0x1afc8ce2ca0>
2021-02-02T20:37:18.082237 image/svg+xml Matplotlib v3.3.3, https://matplotlib.org/
In [5]:
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(); 
2021-02-02T20:37:19.076362 image/svg+xml Matplotlib v3.3.3, https://matplotlib.org/
In [ ]: