# Interactively plot solution & approximations
# Set up controls for interactive plots
def showCheckBox(*args, **kwargs):
return checkbox(*args, **kwargs)
def colorSelector(*args, **kwargs):
return color_selector(*args, label = 'Color', hide_box = True, widget = 'jpicker', **kwargs)
# The same transparency for each curve
transparency = 0.5
lineStyles = ('-', '--', '-.', ':')
def lineStyleSelector(*args, **kwargs):
return selector(*args, values = lineStyles, label = 'Style', **kwargs)
thicknesses = (1, 2, 3)
def thicknessSelector(*args, **kwargs):
return selector(*args, values = thicknesses, label = 'Thickness', **kwargs)
# Number of points on each curve
nPoints = int(1001)
# Make the plots
@interact(layout = [['log10Epsilon'],
['EShown', 'EColor', 'EStyle', 'EThickness'],
['yC0Shown', 'yC0Color', 'yC0Style', 'yC0Thickness'],
['yC1Shown', 'yC1Color', 'yC1Style', 'yC1Thickness']])
def plotSeries(log10Epsilon = slider(-3, log(0.5, 10), default = -2,
label = '$\log_{10} \epsilon$'),
EShown = showCheckBox(label = 'Exact Solution'),
EColor = colorSelector(default = (0, 0, 0)),
EStyle = lineStyleSelector(default = '--'),
EThickness = thicknessSelector(),
yC0Shown = showCheckBox(label = '1-Term Composite Solution'),
yC0Color = colorSelector(default = (1, 0, 0)),
yC0Style = lineStyleSelector(),
yC0Thickness = thicknessSelector(),
yC1Shown = showCheckBox(label = '2-Term Composite Solution'),
yC1Color = colorSelector(default = (0, 1, 0)),
yC1Style = lineStyleSelector(),
yC1Thickness = thicknessSelector()):
epsilon = 10^log10Epsilon
html(r'$$\epsilon = %s$$' % latex(epsilon))
solutionPlots = []
absErrorPlots = []
relErrorPlots = []
# Add boundary points
solutionPlots.append(point([(0, 0), (1, 1)], color = 'black', size = 20))
if yC0Shown:
solutionPlots.append(plot(yC0(epsilon = epsilon), x, 0, 1,
plot_points = nPoints,
color = yC0Color, alpha = transparency,
linestyle = yC0Style, thickness = yC0Thickness))
absErrorPlots.append(plot((yE - yC0)(epsilon = epsilon), x, 0, 1,
plot_points = nPoints,
color = yC0Color, alpha = transparency,
linestyle = yC0Style, thickness = yC0Thickness))
relErrorPlots.append(plot(((yE - yC0) / yE)(epsilon = epsilon), x, 0, 1,
plot_points = nPoints,
color = yC0Color, alpha = transparency,
linestyle = yC0Style, thickness = yC0Thickness))
if yC1Shown:
solutionPlots.append(plot(yC1(epsilon = epsilon), x, 0, 1,
plot_points = nPoints,
color = yC1Color, alpha = transparency,
linestyle = yC1Style, thickness = yC1Thickness))
absErrorPlots.append(plot((yE - yC1)(epsilon = epsilon), x, 0, 1,
plot_points = nPoints,
color = yC1Color, alpha = transparency,
linestyle = yC1Style, thickness = yC1Thickness))
relErrorPlots.append(plot(((yE - yC1) / yE)(epsilon = epsilon), x, 0, 1,
plot_points = nPoints,
color = yC1Color, alpha = transparency,
linestyle = yC1Style, thickness = yC1Thickness))
if EShown:
solutionPlots.append(plot(yE(epsilon = epsilon), x, 0, 1,
plot_points = nPoints,
color = EColor, alpha = transparency,
linestyle = EStyle, thickness = EThickness))
show(sum(solutionPlots), axes_labels = (r'$x$', r'$y(x)$'))
show(sum(absErrorPlots), axes_labels = (r'$x$', 'Abs. Err.'))
show(sum(relErrorPlots), axes_labels = (r'$x$', 'Rel. Err.'))
|
Click to the left again to hide and once more to show the dynamic interactive window
|