restart;
###########################################################
# This maplet is designed for lab 12, which
# explores the concept of uniform continuity
###########################################################with (Maplets[Elements]):
with (plots):###########################################################
# A procedure to create the function for a given
# value of n
###########################################################
makeFcn := proc(m)
local fcn, F, f; global x, n;
use Maplets[Tools]in
fcn := Get('TF2'::algebraic);
end use:
F := subs(n=m, fcn);
f := unapply(F, x);
end proc:
###########################################################
# A procedure to plot the specified functions over
# an interval
###########################################################
showGraph1 := proc()
local minX, maxX, nvals, num, p, F, S;
use Maplets[Tools]in
nvals := Get('TF3'::list);
minX := Get('TF4'::numeric);
maxX := Get('TF5'::numeric);
end use:
F := makeFcn(nvals[1]);
S := {F(x)};
num := nops(nvals);
for p from 2 to num do
F := makeFcn(nvals[p]);
S := S union {F(x)};
od:
plot(S,x=minX..maxX);
end proc:
###########################################################
# A procedure to calculate the value of the
# sequence for a given n and x0
###########################################################
calcValue := proc()
local fn, x0, f;
use Maplets[Tools]in
x0 := Get('TF6'::numeric);
fn := Get('TF7'::numeric);
end use:
f := makeFcn(fn);
f(x0);
end proc:
###########################################################
# A procedure to plot the specified functions
# evaluated at x0 over an interval
###########################################################
showGraph2 := proc()
local x0, startn, endn;
use Maplets[Tools]in
x0 := Get('TF6'::numeric);
startn := Get('TF9'::numeric);
endn := Get('TF10'::numeric);
end use:
pointplot({seq([x0,makeFcn(n)(x0)], n=startn..endn)});
end proc:
###########################################################
# A procedure to plot the specified functions
# evaluated at x0 along with the entire functions
# over an interval
###########################################################
showGraph3 := proc()
local startn, endn, minX, maxX, A, B;
use Maplets[Tools]in
startn := Get('TF9'::numeric);
endn := Get('TF10'::numeric);
minX := Get('TF11'::numeric);
maxX := Get('TF12'::numeric);
end use:
A := showGraph2();
B:= plot({seq(makeFcn(n)(x), n=startn..endn)}, x=minX..maxX);
display(A,B);
end proc:
###########################################################
# A procedure to plot the function from Window 1
# along with the epsilon band for the pointwise limit
###########################################################
showLimit := proc()
local minX, maxX, F, r1, r2, r3, e1, e2, e3, num, L, eps, lim, B; global n;
use Maplets[Tools]in
num := Get('TF13'::numeric);
minX := Get('TF4'::numeric);
maxX := Get('TF5'::numeric);
eps := Get('TF16'::numeric);
end use:
if num = 1 then
use Maplets[Tools]in
r1 := Get('TFR1'::boolean);
e1 := Get('TFE1'::algebraic);
end use:
L := x->e1;
elif num = 2 then
use Maplets[Tools]in
r1 := Get('TFR1'::boolean);
e1 := Get('TFE1'::algebraic);
r2 := Get('TFR2'::boolean);
e2 := Get('TFE2'::algebraic);
end use:
L := x->piecewise(r1, e1, r2, e2);
else
use Maplets[Tools]in
r1 := Get('TFR1'::boolean);
e1 := Get('TFE1'::algebraic);
r2 := Get('TFR2'::boolean);
e2 := Get('TFE2'::algebraic);
r3 := Get('TFR3'::boolean);
e3 := Get('TFE3'::algebraic);
end use:
L := x->piecewise(r1, e1, r2, e2, r3, e3);
fi;
F := showGraphLim();
B := plot({L(x)-eps, L(x)+eps}, x=minX..maxX, discont=true, style=point, color=cyan);
display({F, B});
end proc:
###########################################################
# A procedure to plot the function from Window 1
# along with the pointwise limit
###########################################################
showGraphLim:=proc()
local minX, maxX, F, r1, r2, r3, e1, e2, e3, num, L, eps, lim, B; global n;
use Maplets[Tools]in
num := Get('TF13'::numeric);
minX := Get('TF4'::numeric);
maxX := Get('TF5'::numeric);
eps := Get('TF16'::numeric);
end use:
if num = 1 then
use Maplets[Tools]in
r1 := Get('TFR1'::boolean);
e1 := Get('TFE1'::algebraic);
end use:
L := x->e1;
elif num = 2 then
use Maplets[Tools]in
r1 := Get('TFR1'::boolean);
e1 := Get('TFE1'::algebraic);
r2 := Get('TFR2'::boolean);
e2 := Get('TFE2'::algebraic);
end use:
L := x->piecewise(r1, e1, r2, e2);
else
use Maplets[Tools]in
r1 := Get('TFR1'::boolean);
e1 := Get('TFE1'::algebraic);
r2 := Get('TFR2'::boolean);
e2 := Get('TFE2'::algebraic);
r3 := Get('TFR3'::boolean);
e3 := Get('TFE3'::algebraic);
end use:
L := x->piecewise(r1, e1, r2, e2, r3, e3);
fi;
F := showGraph1();
B := plot(L(x), x=minX..maxX, discont=true, style=point, color=blue);
display({F, B});
end proc:
mapletA:= Maplet(
'onstartup'=RunWindow('W1'),
###########################################################
# Window 1 - User enters sequence and graphs desired
# values of n over an interval
###########################################################
Window['W1']('title'="Enter Sequence and Graph on Interval", [
["Enter formula in terms of x and n:", TextField['TF2']()],
[" "],
["Enter n values:", TextField['TF3']('value'="[ ]"), HorizontalGlue()],
["Minimum x:", TextField['TF4'](5), "Maximum x:", TextField['TF5'](5)],
[Plotter['PL1']()],
[Button("Show Graph", Evaluate('PL1'='showGraph1')), HorizontalGlue(),
Button("Next", Action(CloseWindow('W1'), RunWindow('W2')))]
]),
###########################################################
# Window 2 - User enters value for x0 and plots
# specified functions evaluated at x0
###########################################################
Window['W2']('title'="Examine at Single Point", [
["Enter x0:", TextField['TF6'](5), HorizontalGlue(), HorizontalGlue(),
HorizontalGlue()],
["Enter n value:", TextField['TF7'](5), HorizontalGlue(),
TextField['TF8'](10, 'editable'=false),
Button("Calculate f[n](x0)", Evaluate('TF8'='calcValue')),
HorizontalGlue()],
["Minimum n:", TextField['TF9'](5), "Maximum n:", TextField['TF10'](5)],
["Minimum x:", TextField['TF11'](5), "Maximum x:", TextField['TF12'](5)],
[Plotter['PL2']()],
[Button("Show Points Only", Evaluate('PL2'='showGraph2')),
Button("Show Points and Whole Functions", Evaluate('PL2'='showGraph3')),
Button("Back", Action(CloseWindow('W2'), RunWindow('W1'))),
Button("Next", Action(CloseWindow('W2'), RunWindow('W3')))]
]),
###########################################################
# Window 3 - User enters pointwise limit and
# examines uniform convergence
###########################################################
Window['W3']('title'="Examine Uniform Convergence", [
["Enter pointwise limit"],
["Enter number of piecewise definitions:", TextField['TF13'](5)],
["Range 1:", TextField['TFR1'](10), "Expression 1:", TextField['TFE1'](10)],
["Range 2:", TextField['TFR2'](10), "Expression 2:", TextField['TFE2'](10)],
["Range 3:", TextField['TFR3'](10), "Expression 3:", TextField['TFE3'](10)],
["Epsilon:", TextField['TF16'](5)],
[Plotter['PL3']()],
[Button("Show Graph", Evaluate('PL3'='showGraphLim')),
Button("Add Epsilon Band", Evaluate('PL3'='showLimit'))],
[Button("Exit", Shutdown()), Button("Restart", Action(CloseWindow('W3'),
RunWindow('W1'), SetOption('TF2'=""), SetOption('TF3'="[ ]"),
SetOption('TF4'=""), SetOption('TF5'=""), SetOption('TF6'=""),
SetOption('TF7'=""), SetOption('TF8'=""), SetOption('TF9'=""),
SetOption('TF10'=""), SetOption('TF11'=""), SetOption('TF12'=""),
SetOption('TF13'=""), SetOption('TF16'=""), SetOption('TFR1'=""),
SetOption('TFE1'=""), SetOption('TFR2'=""), SetOption('TFE2'=""),
SetOption('TFR3'=""), SetOption('TFE3'=""),
Evaluate('PL1'="plot(undefined, x=0..10,axes=none)"),
Evaluate('PL2'="plot(undefined, x=0..10,axes=none)"),
Evaluate('PL3'="plot(undefined, x=0..10,axes=none)"))),
Button("Back", Action(CloseWindow('W3'), RunWindow('W2')))]
])
):Maplets[Display](mapletA);restart;