# Interactively plot solution & approximation.
# Number of points on each curve.
npoints = 1001
# Plotting styles.
perturbation_style = {'color': 'red',
'linestyle': '-',
'alpha': 0.5}
numerical_style = {'color': 'black',
'linestyle': '--',
'alpha': 0.5}
endpoints_style = {'color': 'black',
'size': 20}
# Make the plots.
@interact
def plot_solutions(log10epsilon = slider(log(0.03, 10),
log(0.3, 10),
default = -1,
label = '$\log_{10} \epsilon$')):
epsilon = 10^log10epsilon
html(r'$$\epsilon = %s$$' % latex(epsilon))
plots = []
# Perturbation solution.
plots.append(plot(y_perturbation0(epsilon = epsilon), x, 0, 1,
plot_points = npoints,
**perturbation_style))
# Numerical solution.
x_numerical = srange(xl, xr, (xr - xl) / (npoints - 1),
include_endpoint = true)
y_numerical = BVP(RHS, x_numerical, yl, yr, epsilon).solve()
plots.append(line(zip(x_numerical, y_numerical),
**numerical_style))
# Add boundary points.
plots.append(point([(xl, yl), (xr, yr)],
**endpoints_style))
show(sum(plots),
axes_labels = (r'$x$', r'$y(x)$'))
|
Click to the left again to hide and once more to show the dynamic interactive window
|