MathGroup Archive 2010

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

Search the Archive

Re: elementary questio about packages

  • To: mathgroup at smc.vnet.net
  • Subject: [mg108321] Re: elementary questio about packages
  • From: Albert Retey <awnl at gmx-topmail.de>
  • Date: Sat, 13 Mar 2010 07:59:22 -0500 (EST)
  • References: <hndate$d81$1@smc.vnet.net>

Hi,

> 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]]]

I think this example is one of those where there is absolutely no gain
in providing the results as a list of rules. Although many Mathematica
functions do so, there are just as many which don't! Returning results
in the form of rules ony makes sense when there are symbol names
provided with the call of the function, e.g. as in Solve, NSolve,
DSolve, NMinimize and the like. Others, like e.g. LinearSolve,
LeastSquares, LinearProgramming and many more only return vectors and no
rules, since returning rules make no sense for them. For your example
there is also no benefit in returning rules, so I would strongly
recommend to just return the vector that minimizes the contructed
expression, which also solves your problems with the package. This is
how I would define the function:

trivialfunc[ind_, depend_] :=
 Module[{letsee, ineq1, ineq2, func, result},
  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};
  result = NMinimize[Flatten[{func, ineq1, ineq2}], Flatten[letsee]];
  {result[[1]], Flatten[letsee] /. result[[2]]}
  ]

hth,

albert



  • Prev by Date: Re: Re: bad Mathieu functions
  • Next by Date: Putting controls next to graphics in the Manipulate Display area
  • Previous by thread: Re: elementary questio about packages
  • Next by thread: Re: elementary questio about packages