Do you know how can I find minimum/maximum of a simulation written in a Module. The simulation calculates a potential value to a territory after some steps.

It would seem like this:

g[x1_,x2_,x3_,x4_,x5_,x6_] := Module[{x1,x2,x3,x4,x5,x6}, some code calling a simulator software]

So I would like to reach a maximum potential according to the parameters. All parameters should vary between [-2 ... 0 .. 2], with stepsize 1 discretely. So all variations are 5^6, I don't have so much time and resource to calculate each variation.

Can you advise me some code or algorithm where I only have to put the name of the target function?

  • 1
    $\begingroup$ Uh... NMinimize/NMaximize? FindMinimum/FindMaximum? Read their documentation, try it, and if you have any trouble, you can update the question to get some help. $\endgroup$ – Oleksandr R. Jan 9 '15 at 1:15

Define so it only exists for explicitly numeric intput, as


Then can do

vars = {x1,x2,x3,x4,x5,x6};
    Thread[-2<=#<=2&, vars]}, vars]

There are ways to make this slightly cleaner, but that's the idea. The reason to define only for numeric input is to make it effectively a "black box" function, so that no symbolic processing will be attempted.

If NMinimize is too slow or not giving viable results, could try FindMinimum but I don't think it will directly accept the integrality constraints for a nonlinear problem. So you'd probably need to use some penalty term approach involving, for each variable, (xj-Round[xj])^2 or some such.

  • $\begingroup$ Thank you for answer, I am going to try it and report :) $\endgroup$ – pnz Jan 10 '15 at 2:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.