Re: problems with NMinimize

*To*: mathgroup at smc.vnet.net*Subject*: [mg109363] Re: problems with NMinimize*From*: Bill Rowe <readnews at sbcglobal.net>*Date*: Fri, 23 Apr 2010 03:49:45 -0400 (EDT)

On 4/22/10 at 6:43 AM, ngb at ecs.soton.ac.uk (Neil Broderick) wrote: >Hi, I am trying to use NMinimize to find the solutions to various >numerical equations and I keep getting error messages concerning >non-numerical values. For example consider the following: >In[2]:= NMinimize[Abs[NIntegrate[Sin[x], {x, -a, b}]]^2, {a, b}] <error messages snipped> Even if this did work as you expected with no error messages, this would be a very inefficient way to solve the problem. NMinimize works by repeatedly evaluating the expression to be minimized. That means the numerical integration problem is repeatedly solved. In this case, there is a symbolic result for the integral. So doing: In[4]:= int = Integrate[Sin[x], {x, -a, b}] Out[4]= cos(a)-cos(b) And this clearly is zero for Abs[a]==Abs[b]. So, any pair of numbers satisfying this last will be a minimum for the square of the absolute value for the integral. But if you didn't want to find the minimum by inspection, then doing In[5]:= NMinimize[Abs[int], {a, b}] Out[5]= {4.80727*10^-14,{a->0.0961182,b->0.0961182}} returns one of many possible solutions. Note, I didn't bother with squaring the absolute value since minimizing the absolute value is the same as minimizing the square of the absolute value.