Re: how to drop ContextPath when printing from a package?
- To: mathgroup at smc.vnet.net
- Subject: [mg116424] Re: how to drop ContextPath when printing from a package?
- From: DrMajorBob <btreat1 at austin.rr.com>
- Date: Mon, 14 Feb 2011 04:28:34 -0500 (EST)
Better, I think, to give the package user control of what variable is used
in the result:
myFit[data_, var_] :=
Module[{f}, f = FindFit[data, a + b var, {a, b}, var];
a + b var /. f]
myFit[{{1, 2.2}, {2, 3.8}, {3, 6}, {4, 8.4}}, x]
-0.1 + 2.08 x
Bobby
On Sun, 13 Feb 2011 02:05:30 -0600, Sjoerd C. de Vries
<sjoerd.c.devries at gmail.com> wrote:
> Hi Ted,
>
> I assume your variable is local to a package that contains the
> variable. Apart from the package context I further assume that your
> module basically does something like:
>
> myFit[data_] :=
> Module[{x, f},
> f = FindFit[data, a + b x, {a, b}, x];
> a + b x /. f
> ]
>
> which yields something like:
>
> In[276]:= myFit[{{1, 2.2}, {2, 3.8}, {3, 6}, {4, 8.4}}]
>
> Out[276]= -0.1 + 2.08 x$142961
>
> In my opinion, it is never a good idea to return a local variable. One
> solution is, of course, to use a different variable in your module, so
> not x, or not to return the fit in terms of x. If returning a model in
> terms of x is necessary another solution might be
>
> myFit[data_] :=
> Module[{x, f},
> f = FindFit[data, a + b x, {a, b}, x];
> a + b Symbol["x"] /. f
> ]
>
> In[278]:= myFit[{{1, 2.2}, {2, 3.8}, {3, 6}, {4, 8.4}}]
>
> Out[278]= -0.1 + 2.08 x
>
> Cheers -- Sjoerd
>
>
>
>
>
> On Feb 11, 10:14 am, Ted Sariyski <tsari... at craft-tech.com> wrote:
>> Hi,
>> I have a module, which make use of FindFit[data,model,par,x] and
>> returns the model and a plot of data and the fit curve. I want to use
>> the model as a PlotLabel but
>> instead of
>>
>> y=1.19623+1048.91 x^0.733809
>>
>> I get
>>
>> y=1.19623+1048.91 initData`Private`x$^0.733809
>>
>> How can I get rid of the ContextPath initData`Private`?
>> Thanks in advance,
>> --Ted
>
>
--
DrMajorBob at yahoo.com