| Original Message (ID '348531') By yehuda: |
| No guesses need to be done when one is messing with packages. In addition I wonder why you use replacement rule to change the function to be plotted
So,
1. load you package
BeginPackage["testPlotPckg`"]
testPlot::usage = "None until I get it to work.";
Begin["`Private`"];
testPlot[eqn_]:=Module[{},Plot[y[x]/.eqn,{x,0,2}]]
End[ ];
EndPackage[];
2. Check
?? "testPlotPckg`*"
3. notice the answer
testPlot[testPlotPckg`Private`eqn_]:=Module[{},Plot[testPlotPckg`Private`y[testPlotPckg`Private`x]/. testPlotPckg`Private`eqn,{testPlotPckg`Private`x,0,2}]]
4. that is, x is a local variable, AND y is a local variable too. notice their context, so the way you call the function will never work
5. Now, change the definition of testPlot into
BeginPackage["testPlotPckg`"]
testPlot::usage = "None until I get it to work.";
Begin["`Private`"];
testPlot[expr_]:=Module[{},Plot[expr[x],{x,0,2}]]
End[ ];
EndPackage[];
6. call is with a function as
testPlot[ #^2&]
or
testPlot[Function[z,z^2]]
will work
7. also (which you will find the most convenient)
g[x_] := Sin[10x]
tetPlot[g]
will work too
yehuda
|
|