MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: how to drop ContextPath when printing from a package?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg116389] Re: how to drop ContextPath when printing from a package?
  • From: "Sjoerd C. de Vries" <sjoerd.c.devries at gmail.com>
  • Date: Sun, 13 Feb 2011 03:05:30 -0500 (EST)
  • References: <200812020542.AAA19141@smc.vnet.net> <ij2uks$7j8$1@smc.vnet.net>

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



  • Prev by Date: Re: list manipulation
  • Next by Date: Re: solution of equation
  • Previous by thread: how to drop ContextPath when printing from a package?
  • Next by thread: Re: how to drop ContextPath when printing from a package?