 
 
 
 
 
 
Re: Unappropiate context in a package
- To: mathgroup at smc.vnet.net
- Subject: [mg29600] Re: Unappropiate context in a package
- From: "Allan Hayes" <hay at haystack.demon.co.uk>
- Date: Wed, 27 Jun 2001 05:12:35 -0400 (EDT)
- References: <9h8m8n$qss$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Guillermo,
You are right to suspect  t.
When your package code below is loaded
BeginPackage["test`test`"];
qContinuousTest::usage = "qContinuous[test]";
Begin["`Private`"];
 qContinuousTest[acute_, conti_, t2_] :=
    Module[{tau, a, c, r, t1},
        a[t1_] = acute /. t -> t1;
        c[t1_] = conti /. t -> t1;
       r = Integrate[ExpandAll[a[tau]]*c[t1 - tau], {tau, 0, t1}];
        r /. t1 ->t2
    ];
 End[];
 Protect[qContinuousTest];
 EndPackage[];
The t in in the stored version of
    a[t1_] = acute /. t -> t1;
    c[t1_] = conti /. t -> t1;
translate to  test`test`t;
But when
    qContinuousTest[Exp[(-k)*t], 0.1, 2]
is evaluated the t in Exp[(-k)*t], as inserted into the code for
qContinuousTest, remains just  t  , so no replacement takes place.
A simple way to get round this is to have the user specify the active
variable in acive and conti (this conforms to what we do with Integrate for
example).
Thus
Quit[] (* evaluate this in its own line*)
BeginPackage["test`test`"];
qContinuousTest::usage="qContinuous[test]";
Begin["`Private`"];
qContinuousTest[acute_,conti_,{t_,t2_}]:=Module[{tau,a,c,r,t1},
      a[t1_]=acute/.t\[Rule]t1;
      c[t1_]=conti/.t\[Rule]t1;
      r=Integrate[a[tau]*c[t1-tau],{tau,0,t1}];r/.t1\[Rule]t2
      ];
End[];
Protect[qContinuousTest];
EndPackage[]
TEST
qContinuousTest[Exp[(-k)*t],0.1 ,{t,2}]
        0.1*(1/k - 1/(E^(2*k)*k))
HERE IS A VARIANT
Quit[]
BeginPackage["test`test`"];
qContinuousTest::usage="qContinuous[test]";
Begin["`Private`"];
qContinuousTest[acute_,conti_,{t_,t2_}]:=Module[{tau,a,c},
      a=Function[t,acute];
      c= Function[t,conti];
      Integrate[a[tau]*c[t-tau],{tau,0,t2}]
      ];
End[];
Protect[qContinuousTest];
EndPackage[]
TEST
qContinuousTest[Exp[(-k)*t],0.1 ,{t,2}]
        0.1*(1/k - 1/(E^(2*k)*k))
--
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565
"Guillermo Sanchez" <guillerm at gugu.usal.es> wrote in message
news:9h8m8n$qss$1 at smc.vnet.net...
> I have the following expresion:
>
> qContinuousTest1[acute_, conti_, t2_] := Module[{tau, a, c, r, t1},
> a[t1_] = acute /. t -> t1; c[t1_] = conti /. t -> t1;
> r = Integrate[ExpandAll[a[tau]]*c[t1 - tau], {tau, 0, t1}]; r /. t1 ->
> t2];
> Simplify[qContinuousTest1[Exp[(-k)*t], 0.1, 2]]
>
> (*It work fine:*)
>
> Out[] := (0.1 - 0.1/E^(2*k))/k
>
> Now I wish to use the same expresion in a package but some thing is in
> unpropiate context. I thing is t, but how I can correct this problem.
>
> Note: "acute" and "conti" are always functions of t.
>
> Thanks
>
> BeginPackage["test`test`"]
>
> qContinuousTest::usage = "qContinuous[test]"
>
> Begin["`Private`"]
>
> qContinuousTest[acute_, conti_, t2_] := Module[{tau, a, c, r, t1},
> a[t1_] = acute /. t -> t1; c[t1_] = conti /. t -> t1;
> r = Integrate[ExpandAll[a[tau]]*c[t1 - tau], {tau, 0, t1}]; r /. t1 ->
> t2];
> End[]
>
> Protect[qContinuousTest];
>
> EndPackage[]
>
> Simplify[qContinuousTest[Exp[(-k)*t], 0.1, 2]]
>
> Out[]:= 0.2/E^(k*t)
>

