restart:
Plot Tan
P. Yasskin
with(Maplets[Tools]):
with(Maplets[Elements]):
with(plots);
StartEngine();
plotfunc:=proc()
global userfunc, userinterv, p1;
userfunc:=Get(func::algebraic):
userinterv:=Get(interv::range):
p1:=plot(userfunc, x=userinterv, thickness=2, color=green);
Set(myplot=p1)
end proc:
plottan:=proc()
uses plots;
global userfunc, userinterv, userpoint, p1, p2, duserfunc, tanfunc;
userpoint:=Get(point::realcons):
duserfunc:=diff(userfunc,x);
tanfunc:=eval(userfunc,x=userpoint)+eval(duserfunc,x=userpoint)*(x-userpoint);
p2:=plot(tanfunc, x=userinterv, thickness=2, color=blue);
Set(myplot=display(p1,p2))
end proc:
PlotTan:=Maplet(onstartup = RunWindow(MAIN),
Window[MAIN](title="Plot Tangent Demo",
[ [ "Type in a function of x, and an interval a..b for x."
],
[ "Function:", TextField[func](width=25, background=turquoise)
],
[ "Interval:", TextField[interv](width=25, background=turquoise)
],
[ Button("Plot It", onclick=A1, background=tan),
Button("Good Bye", Shutdown(), background=pink)
]
]
),
Window[PlotIt](title="The Plot",
[ [ Plotter[myplot](width=300, height=300)
],
[ "Add the tangent line at the point x= ",
TextField[point](width=5, background=turquoise)
],
[ Button("Plot It", Evaluate(function = "plottan"), background=tan),
Button("Close", CloseWindow(PlotIt), background=pink)
]
]
),
Action[A1](RunWindow(PlotIt), Evaluate(function = "plotfunc"))
):
Maplets[Display]( PlotTan );