Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'Plotting in package' topicStudent Support Forum > General > Archives > "Plotting in package"

< Previous Comment | Next Comment >Help | Reply To Comment | Reply To Topic
Author Comment/Response
yehuda
02/21/13 03:30am

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


URL: ,

Subject (listing for 'Plotting in package')
Author Date Posted
Plotting in package Abed Alnaif 02/18/13 8:31pm
Re: Plotting in package yehuda 02/21/13 03:30am
Re: Re: Plotting in package Abed Alnaif 02/26/13 6:16pm
< Previous Comment | Next Comment >Help | Reply To Comment | Reply To Topic