MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Forcing output in FindMinimum




Hossein Kazemi wrote in message <6k7d8d$1if@smc.vnet.net>...
>Is there a way to force FindMinimum to give an answer even if it does
>not want to.  For example, when one uses:
>
>In[1]: FindMinimum[f[x1,x2],{x1,start,min,max},{x2,start,min,max}]
>
>Mathematica may send a message that it has moved outside the range, but
>it does give the last values of x1 and x2.  Is there a way to force it
>to produce the last values it used for x1 and x2.
>
>Thank you
>
>Hossein Kazemi
>Univ of Mass
>
>

Hossein,

The following is based on an earlier posting of David Withoff

In[1]:=
Clear[GetParameter]
In[2]:=
Attributes[GetParameter]= HoldAll;
In[3]:=
GetParameter[expr_, n_]:=
  ( Unprotect[Message];
    Message[ n,  p_,q___]:=Null/;{par =p;False};
    Protect[Message];
       Check[expr,par,n]
  )

In[4]:=
GetParameter[FindMinimum[-Sin[Pi x],{x,0,0,.3}],
 FindMinimum::regex]

FindMinimum::"regex":
    "Reached the point 0.3` which is outside the region {{0., 0.3}}

Out[4]=
0.3

------------------------------------------------------------- Allan
Hayes
Training and Consulting
Leicester UK
http://www.haystack.demon.co.uk
hay@haystack.demon.co.uk
voice: +44 (0)116 271 4198
fax: +44(0)116 271 8642





  • Prev by Date: Re: Solution for a System of ODEs and equations
  • Next by Date: Re: red-green stereograms
  • Prev by thread: Forcing output in FindMinimum
  • Next by thread: Re: Forcing output in FindMinimum