From: Francisco Gutierrez on 11 Mar 2010 06:37 Dear List: I made a package with a function that has a minimization. The minimization returns, as should be, the value of the optimization, and then the values of the variables, in the form {z1->10,z2->20,z3->50}. In the notebook, this works perfectly well. In the package, however, the function throws back the variables in the form {contextname`z1->10,contextname`z2->20}. This is obnoxious, and makes the result much harder to utilize. How can I avoid this? I tried deleting Begin["`Private`"], but then I got a completely crazy result. What should I do? Fg
From: Patrick Scheibe on 11 Mar 2010 07:48 Hi, like your function-symbols, the symbols z1, z2, ... need to be exported by giving them a usage. Cheers Patrick On Thu, 2010-03-11 at 06:37 -0500, Francisco Gutierrez wrote: > Dear List: > I made a package with a function that has a minimization. The minimization > returns, as should be, the value of the optimization, and then the values > of the variables, in the form {z1->10,z2->20,z3->50}. > > In the notebook, this works perfectly well. In the package, however, the function throws back the variables in the form {contextname`z1->10,contextname`z2->20}. > This is obnoxious, and makes the result much harder to utilize. How can I avoid this? I tried deleting > Begin["`Private`"], but then I got a completely crazy result. > What should I do? > Fg >
From: becko BECKO on 12 Mar 2010 07:06 Whenever you declare a function in a package that uses some temporary variables, you should use Module to declare those variables. If this does not help, perhaps you should post some code so that the guys here can see where the problem is. > Date: Thu, 11 Mar 2010 06:37:35 -0500 > From: fgutiers2002(a)yahoo.com > Subject: elementary questio about packages > To: mathgroup(a)smc.vnet.net > > Dear List: > I made a package with a function that has a minimization. The minimization > returns, as should be, the value of the optimization, and then the values > of the variables, in the form {z1->10,z2->20,z3->50}. > > In the notebook, this works perfectly well. In the package, however, the function throws back the variables in the form {contextname`z1->10,contextname`z2->20}. > This is obnoxious, and makes the result much harder to utilize. How can I avoid this? I tried deleting > Begin["`Private`"], but then I got a completely crazy result. > What should I do? > Fg
From: Leonid Shifrin on 12 Mar 2010 07:08 Hi Francisco, Depending on the circumstances, another possibility would be to create the needed symbols (z1,z2,etc) in the context they will be used (Global`, say), before the BeginPackage command, and import this context publicly into your package in BeginPackage. This is not as clean a solution as Patrick's (since it couples contexts and assumes a specific work context), but it may be sometimes more convenient - you won't then see the annoying shadowing messages every time when you create z1, z2 in Global` (or whatever is your working context) before loading your package. I guess you can also combine the two approaches: rather than explicitly creating the symbols say in Global` before BeginPackage, you can simply import Global` (or whatever you working context) in BeginPackage, but give these symbols the usage messages in your package anyway. Then, if they don't exist in the target one (Global` here), they will be created in your package and exported just as Patrick suggested. If they exist, usage messages will be added to them in your working context, which I think is also a good thing. Regards, Leonid On Thu, Mar 11, 2010 at 3:48 PM, Patrick Scheibe < pscheibe(a)trm.uni-leipzig.de> wrote: > Hi, > > like your function-symbols, the symbols z1, z2, ... need > to be exported by giving them a usage. > > Cheers > Patrick > > On Thu, 2010-03-11 at 06:37 -0500, Francisco Gutierrez wrote: > > Dear List: > > I made a package with a function that has a minimization. The > minimization > > returns, as should be, the value of the optimization, and then the values > > of the variables, in the form {z1->10,z2->20,z3->50}. > > > > In the notebook, this works perfectly well. In the package, however, the > function throws back the variables in the form > {contextname`z1->10,contextname`z2->20}. > > This is obnoxious, and makes the result much harder to utilize. How can I > avoid this? I tried deleting > > Begin["`Private`"], but then I got a completely crazy result. > > What should I do? > > Fg > > > > >
From: Francisco Gutierrez on 12 Mar 2010 07:09 Right Becko. And thanks to Leonid, David, and Patrick for their answers. But maybe to make it very clear I should provide a an example. Take the following function: trivialfunc[ind_, depend_] := Module[{letsee, ineq1, ineq2, func}, letsee = Array[L, Length[depend]]; ineq1 = MapThread[ GreaterEqual, {letsee, Table[0, {Length[letsee]}]}]; ineq2 = MapThread[ GreaterEqual, {ind - letsee, Table[0, {Length[letsee]}]}]; func = {ind.letsee}; NMinimize[Flatten[{func, ineq1, ineq2}], Flatten[letsee]]] Of course, it should send all the L's to 0. Note that the L's vary in size, according to the length of the two variables. I make a package called trivial, and run the function with an x and a y. x={1,2,3,4,5} y={6,7,8,9,10} trivialfunc[y,y] And the output is: {0.,{trivial2`Private`L[1]->0.,trivial2`Private`L[2]->0.,trivial2`Private`L[3]->0.,trivial2`Private`L[4]->0.,trivial2`Private`L[5]->0.}} If I eliminate the Private I get pure nonsense, and if a declare the Ls in the module I get something of the form L$something, which I do not want either. I would want it to be simply L[1]->0, etc, for a varying number of L's. Thank you for any help Fg --- On Thu, 3/11/10, becko BECKO <becko565(a)hotmail.com> wrote: From: becko BECKO <becko565(a)hotmail.com> Subject: RE: elementary questio about packages To: fgutiers2002(a)yahoo.com, mathgroup(a)smc.vnet.net Date: Thursday, March 11, 2010, 7:52 AM Whenever you declare a function in a package that uses some temporary variables, you should use Module to declare those variables. If this does not help, perhaps you should post some code so that the guys here can see where the problem is. > Date: Thu, 11 Mar 2010 06:37:35 -0500 > From: fgutiers2002(a)yahoo.com > Subject: elementary questio about packages > To: mathgroup(a)smc.vnet.net > > Dear List: > I made a package with a function that has a minimization. The minimization > returns, as should be, the value of the optimization, and then the values > of the variables, in the form {z1->10,z2->20,z3->50}. > > In the notebook, this works perfectly well. In the package, however, the function throws back the variables in the form {contextname`z1->10,contextname`z2->20}. > This is obnoxious, and makes the result much harder to utilize. How can I avoid this? I tried deleting > Begin["`Private`"], but then I got a completely crazy result. > What should I do? > Fg >
|
Next
|
Last
Pages: 1 2 Prev: bad Mathieu functions Next: Struggling with FindFit for a model which takes results from |