Re: Numerical optimization

*To*: mathgroup at smc.vnet.net*Subject*: [mg120217] Re: Numerical optimization*From*: David Bailey <dave at removedbailey.co.uk>*Date*: Wed, 13 Jul 2011 03:12:39 -0400 (EDT)*References*: <iv6guj$s6r$1@smc.vnet.net>

On 08/07/2011 10:00, Equilib wrote: > Hi all, > I'm new to numerical optimization routines and since I get no results > I worry that I may have made errors in my setup. I would like to > maximize function f(p1,p2,s,c2,g) using the variables p1, p2, s. The > parameters c2 and g are both in the interval (0,1). Hence I want a > large matrix with solutions to the maximization problem for all > combinations of c2 and g. > > I set it up as follows: > Do[NMaximize[{f, "Constraints"}, {s, p1, p2}], {c2, 0, 1, 0.1}, {g, 0, > 1, 0.1}] > > but get a page full of different error mesages and no output. Can > anyone see the programming errors and maybe suggest an alternative > route? > > Thanks a lot, > Petter > A few suggestions: 1) Pick some parameter values, and run one NMaximize calculation to check things out before embedding this in a Do loop. 2) Usually if you get a string of error messages, the first few are the most useful - so why not post them for us to look at. 3) Unless your function, 'f' contains a Print, you are not going to obtain any output from your loop - you need to write something like: Do[ result=NMaximize[{f, "Constraints"}, {s, p1, p2}]; Print["c2=",c2," g=",g,": ",result], {s, p1, p2}], {c2, 0, 1, 0.1}, {g, 0, > 1, 0.1}] NMaximize can generate some errors/warnings naturally in certain conditions, so it is conceivable that the above is all you need. David Bailey http://www.dbaileyconsultancy.co.uk