[Date Index]
[Thread Index]
[Author Index]
Re: Why Plot cannot run under package?
*To*: mathgroup at smc.vnet.net
*Subject*: [mg39653] Re: [mg39628] Why Plot cannot run under package?
*From*: Omega Consulting <info at omegaconsultinggroup.com>
*Date*: Thu, 27 Feb 2003 00:33:26 -0500 (EST)
*Sender*: owner-wri-mathgroup at wolfram.com
This is a context issue.
All symbols in you package are either in the System`,
Enhancements`DiscoverRoots1`, or Enhancements`DiscoverRoots1`Private
contexts. If it is a System` symbol it is recognized as such. Any
non-System` symbols used between the BeginPackage and Begin commands are in
the Enhancements`DiscoverRoots1` context. All other symbols are put in the
Enhancements`DiscoverRoots1`Private context.
This means that the x in you function is in the
Enhancements`DiscoverRoots1`Private context. But the x in the kk variable
is in the Global` context. To do what you want, you should do something like
DiscoverRoots1[CurveEquation_, {x_, xmin_, xmax_}]:=
Module[{pp},
(pp =
Plot[CurveEquation[x], {x,xmin,xmax}, MaxBend -> 10,
PlotDivision -> 20];
)]
This ensures that the x in the first and second arguments of Plot are the
same variable.
At 01:43 AM 2/26/2003, liwen liwen wrote:
>I want to use the Plot function in Package,so I try the following package:
>
>
>
>BeginPackage["Enhancements`DiscoverRoots1`"]
>
>DiscoverRoots1::usage = " Try the use of Plot in package "
>
>Begin["`Private`"]
>
>
>DiscoverRoots1[CurveEquation_, RootLocation_] :=
> Module[{pp},
> (pp =
> Plot[CurveEquation[x], RootLocation, MaxBend -> 10,
> PlotDivision -> 20];
> )];
>
>End[]
>EndPackage[
>
>I run:
>Needs["Enhancements`DiscoverRoots1`"]
>
>It is OK.
>
>But I try:
>
>Curve1[x_] = Sin[x];
>kk = {x, 0, 40};
>DiscoverRoots1[Curve1, kk]
>
>It alert such message:
>
>Plot::plnr: Curve1[Enhancements`DiscoverRoots1`Private`x] is not a \
>machine-size real number at x = 1.6666666666666667`*^-6.
>
>Plot::plnr: Curve1[Enhancements`DiscoverRoots1`Private`x] is not a \
>machine-size real number at x = 1.6226796629166318`.
>
>Plot::plnr: Curve1[Enhancements`DiscoverRoots1`Private`x] is not a \
>machine-size real number at x = 3.3923519943749474`.
>
>General::stop: Further output of Plot::plnr will be suppressed during this \
>calculation.
>
>But if I run the function under *.nb file, it can runs well.
>
>In[1]:=
>DiscoverRoots1[CurveEquation_,RootLocation_]:=
> Module[{pp},(pp=
> Plot[CurveEquation[x],RootLocation,MaxBend\[Rule]10,
> PlotDivision\[Rule]20];)];
>
>In[2]:=
>Curve1[x_]=Sin[x];
>kk={x,0,40};
>DiscoverRoots1[Curve1,kk]
>
>
>I do not know why the program fails when it is in Package format.
>Please help.
>
>Regards,
>Liwen
--------------------------------------------------------------
Omega Consulting
"The final answer to your Mathematica needs"
http://omegaconsultinggroup.com
Prev by Date:
**Re: Why Plot cannot run under package?**
Next by Date:
**Re: Mathematica Evaluation Process**
Previous by thread:
**Re: Why Plot cannot run under package?**
Next by thread:
**A bug in ConstrainedMin**
| |