I have a .wl
package and a demo .nb
notebook. The package file is testPackage.wl
and it consists of:
BeginPackage["testPackage`"]
testIntegrator::usage =
"Demonstrates an issue with Context in my package"
Begin["`Private`"]
testIntegrator[ v_]:=
Module[
{vSub,odes,vp},
vSub=(v/.{x->x[t]});
odes={
x'[t]==vSub,
x[0]==x0
};
vp=x[t]/.ParametricNDSolve[
odes,
x[t],
{t,0,1},
{x0}];
vp
]
End[]
EndPackage[]
The notebook that runs this code is demos.nb
and it consists of
<< testPackage.wl
pf = testIntegrator[Exp[-x]]
Plot[pf[.1], {t, 0, 1}]
When I run the above notebook, it returns a non-usable ParametricFunction object, which appears to be due to issues with the context of the dependent variables. The function looks like this
In comparison, if I define the function in the notebook itself (rather than in an external .wl
file), I do not have this problem. The function correctly returns this output
How do I correctly handle the variable contexts when defining functions in an external package? I think that my variable substitution (v/.{x->x[t]})
likely may be at fault, but I am unsure how to modify it.