Help with NMinimize
- To: mathgroup at smc.vnet.net
- Subject: [mg82264] Help with NMinimize
- From: Flavio <flavio.cimolin at gmail.com>
- Date: Tue, 16 Oct 2007 03:35:24 -0400 (EDT)
Hi everybody, I can't figure out how to solve this problem with NMinimize, which I want to use in order to test the Nelder and Mead algorithm with an externally evaluated function. I consider the following five argument function (of course this is not my actual minimization function): g[x1,x2,x3,x4,x5]:=Module[{xx1=x1,xx2=x2,xx3=x3,xx4=x4,xx5=x5}, Export[ToString[xx1]<>".txt",xx1]; Return[(xx1-1)^2+(xx2-1)^2-xx3^2+(xx4+1)^2+xx5^2]; ] Now, if I compute g[1,2,3,4,5] I get the correct answer "14", and a file named "1.txt" is created, exactly as expected. But if I use the NMinimize command in this way: NMinimize[{g[x1,x2,x3,x4,x5],constr},{x1,x2,x3,x4,x5},Method- >{"NelderMead",RandomSeed->1},EvaluationMonitor:>Print["x1=",x1]] with these constraints: constr={x1^2<=4&&x2^2<=4&&x3^2<=4&&x4^2<=4&&x5^2<=4}; The minimization is performed, but only a single file, named "x1.txt" is created. The x1 argument in the fuction seems to have the value "x1" rather than its effective value? Can somebody explain me which is the problem with my code, and how can I actually use the value inside the function? I need to use this value because the function g should be replaced by a function that creates a file with the arguments, evaluate a command, and then reads the values obtained by the external program. Thank you very much for your help. Flavio Cimolin