0

I'm sure this has been asked, but I can't seem to find the correct terms to find it.

I have a function that looks something like this

myFunction[data_]:=Module[{result, x, y}, 
      result = NMinimize[ myModel[data, x, y], {x, y}];
      Return[result]
]

When I use it my results look something like

{1234, x$2319->10, y$2319 -> 0.023}

Besides working with global variables, how do I remove the $2319 from x$2319 and y$2319 (ideally as part of myFunction) so I can use the results more easily?

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
mikemtnbikes
  • 679
  • 3
  • 11

2 Answers2

1

Best way to handle this is to pass in symbols from caller that you want to be part of returned expression.

myFunction[data_,x_,y_]:=Module[{result},
result={data,x,y}
];

ClearAll[x,y]
myFunction[{1,2,3},x,y]

Mathematica graphics

No dollars any more. This is how Mathematica does it. For example, NDSolve and DSolve etc... they take in y[x] and also x from user scope so that the result returned will not have $$ in it.

See module-and-local-variable also

Nasser
  • 143,286
  • 11
  • 154
  • 359
0

The solution I like best is to replace Module[] with Block[]. Simple and given in Module and Local variable as pointed out by Nasser (thanks!).

mikemtnbikes
  • 679
  • 3
  • 11
  • 2
    Check what happens if x and y have global values before you call this function. Wanting to localize and wanting to return x and y from the function are kind of contradictory. – Szabolcs Sep 07 '17 at 07:41