Back: Programming
Previous: Module, Block, With
Next: Anonymous Functions
$Context
$ContextPath
Global`
{Global`, System`}
Get["Calculus`VectorAnalysis`"];
$ContextPath
{Calculus`VectorAnalysis`, fDf`, Global`, System`}
BeginPackage[ "newcontext`" ]; (* list all new (nonprivate) functions *) Begin[ "`Private`" ]; (* **** all the new definitions **** *) End[]; (* use Protect[] and SetAttributes[] *) EndPackage[];
BeginPackage[ "fDf`" ];
fdfPlot::usage = "fdfPlot[f,a,b] makes a plot of pure function
f over the range [a,b], and superimposes the
derivative of f as a dotted line.";
Begin["`Private`"];
label[f_] := FontForm[
StringJoin[
"f[x]= ",
ToString[f[x]],
" and f'[x] (dashed line)"],
{"Helvetica-Bold",24}];
fdfPlot[f_, tmin_, tmax_] := Module[
{df, g1, g2}, (* local variables *)
df = D[f[t], t];
g1 = Plot[f[t],{t,tmin,tmax},
PlotStyle->{Thickness[0.005],Hue[0.8]},
DisplayFunction->Identity];
g2 = Plot[df, {t,tmin,tmax},
PlotStyle->{Dashing[{0.01,0.01}],Hue[0.55]},
DisplayFunction->Identity];
Show[g1, g2, PlotLabel->label[f],
DisplayFunction->$DisplayFunction];
]
End[];
Protect[fdfPlot];
EndPackage[];
Get["fDf`"]; (* read the package *)
Context /@ {fdfPlot, label, g1}
{fDf`, fDf`Private`, fDf`Private`}
fdfPlot[ ArcTan[#]-0.5&, -5, 5]
