Re: problems with NMinimize

*To*: mathgroup at smc.vnet.net*Subject*: [mg109387] Re: problems with NMinimize*From*: Bob Hanlon <hanlonr at cox.net>*Date*: Sat, 24 Apr 2010 04:03:06 -0400 (EDT)

\[Beta][coeffs : {_?NumericQ ..}, z_?NumericQ] := coeffs[[1]] + Sum[coeffs[[i]] ChebyshevT[i, z], {i, 2, Length[coeffs]}]; Bob Hanlon ---- Neil Broderick <ngb at ecs.soton.ac.uk> wrote: ============= Bob, thanks for that. It is neater than my work around was that I defined the function recursively if the arguements weren't numeric and then set the recursion limit to 2 to get it to halt. Do you know how I would handle a variable number of arguments? Currently I have a function \[Beta][coeffs_, z_] := coeffs[[1]] + Sum[coeffs[[i]] ChebyshevT[i, z], {i, 2, Length[coeffs]}]; and would like to be able minimise a function involving beta for an arbitrary number of arguments. So how does the NumericQ trick work on a list of variables? cheers, Neil On 22 Apr 2010, at 13:26, Bob Hanlon wrote: > > Define a function that only evaluates for numeric arguments > > f[a_?NumericQ, b_?NumericQ] := > Abs[NIntegrate[Sin[x], {x, -a, b}]]^2 > > NMinimize[f[a, b], {a, b}] > > {7.56317*10^-19,{a->0.131888,b->-0.131888}} > > > Bob Hanlon > > ---- Neil Broderick <ngb at ecs.soton.ac.uk> 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}] > > During evaluation of In[2]:= NIntegrate::nlim: x = -1. a is not a valid limit of integration. >> > > During evaluation of In[2]:= NIntegrate::nlim: x = -1. a is not a valid limit of integration. >> > > During evaluation of In[2]:= NIntegrate::nlim: x = -1. a is not a valid limit of integration. >> > > During evaluation of In[2]:= General::stop: Further output of NIntegrate::nlim will be suppressed during this calculation. >> > > Out[2]= {5.08978*10^-24, {a -> 0.0994414, b -> 0.0994414}} > > My actual problem involves taking Fourier transforms of lists of numbers but you get the picture. Why is > NMinimize putting variables into the function rather than just numbers and is the likely to cause a problem > in some cases? > > regards, > Neil=