Re: Is it possible to access internal variables? [CompoundExpression]

*To*: mathgroup at smc.vnet.net*Subject*: [mg34820] Re: Is it possible to access internal variables? [CompoundExpression]*From*: "Carl K. Woll" <carlw at u.washington.edu>*Date*: Sat, 8 Jun 2002 05:21:36 -0400 (EDT)*References*: <933FF20B19D8D411A3AB0006295069B0286B3A@debis.com>*Sender*: owner-wri-mathgroup at wolfram.com

RE: Is it possible to access internal variables? [CompoundExpression]Hartmut, I think you are being a bit harsh in assessing Arny's intent. He did state that he expected the minimum to lie in a certain range (-1 to 1) but that the minimum might be a LITTLE BIT outside this range. In this situation, the value reported in FindMinimum's error message ought to be rather close to the true minimum. Carl Woll Physics Dept U of Washington ----- Original Message ----- From: Wolf, Hartmut To: mathgroup at smc.vnet.net Sent: Friday, June 07, 2002 1:50 AM Subject: [mg34820] RE: Is it possible to access internal variables? [CompoundExpression] > -----Original Message----- > From: Carl K. Woll [mailto:carlw at u.washington.edu] To: mathgroup at smc.vnet.net > Sent: Friday, June 07, 2002 9:17 AM > Cc: mathgroup at smc.vnet.net > Subject: [mg34820] Re: Is it possible to access internal variables? > [CompoundExpression] > > > Arny (and others), > > Concerning your original question, you can do what you want > as follows: > > First give Message a new definition for the case you are > interested in: > > In[20]:= > Unprotect[Message]; > Message[FindMinimum::"regex",a__/;messageflag]:= > Module[{}, > messageflag=False; > If[ValueQ[messlist],messlist={messlist,{a}},messlist={a}]; > Message[FindMinimum::"regex",a]; > messageflag=True;] > Protect[Message]; > > Now, to see the above in action, consider the example Bob > Hanlon came up > with. > > In[10]:= > f[x_]:=(x-3)(x-4) > > In[15]:= > messageflag=True; > Clear[messlist] > FindMinimum[f[x],{x,2,1,3}] > messageflag=False; > >From In[15]:= > FindMinimum::regex: Reached the point {3.5} which is outside > the region > {{1., 3.}}. > >From In[15]:= > FindMinimum::regex: Reached the point {3.5} which is outside > the region > {{1., 3.}}. > Out[17]= > FindMinimum[f[x], {x, 2, 1, 3}] > > Now, let's see if messlist has the desired information: > > In[19]:= > messlist > Out[19]= > {{{3.5}, {{1., 3.}}}, {{3.5}, {{1., 3.}}}} > > There you go. > > Carl Woll > Physics Dept > U of Washington > > In a message dated 6/1/02 6:18:58 AM, > someone at somewhere.sometime writes: > > -- snipped, quotation below --- > > > > > Dear Carl, you found a clever way to get at the point where FindMinimum stops, because obviously the minimum is out of bounds. Arny wanted this because... [Arny] > > .... I could write a routine using Check to catch errors > > and then expand the range over which FindMinimum is allowed > > to search, but since FindMinimum seems to be getting the appropriate values > > anyway - it tells me the values in its error message - I was wondering > > if there weren't some way to get at those values and use them without > > bothering to write said routine. I was thinking of ... ...but his observation is simply not correct and such all this is of no value for his purpose. Look what happens if I modify the function with a small bump near the minimum: gx[s_, s0_, w_] = D[Exp[-x^2], {x, 1}] /. x -> (s - s0)/w g[x_] := (x - 3)(x - 4) - gx[x, 3.5, .1] Plot[g[x], {x, 1, 5}, PlotRange -> All] In[7]:= FindMinimum[g[x], {x, 2, 1, 3}] From In[7]:= FindMinimum::"regex": "Reached the point \!\({3.5000000002484173`}\) which is \ outside the region \!\({\({1.`, 3.`}\)}\)." Out[7]= FindMinimum[g[x], {x, 2, 1, 3}] Inspecting the plot we see this is certainly not the minimum. Also less contrieved: h[x_] := (x - 3)(x - 4)(x - 1) Plot[h[x], {x, 1, 5}] In[24]:= FindMinimum[h[x], {x, 2, 1, 3}] From In[24]:= FindMinimum::"regex": "Reached the point \!\({5.15416048058637`}\) which is \ outside the region \!\({\({1.`, 3.`}\)}\)." Out[24]= FindMinimum[h[x], {x, 2, 1, 3}] Again 5.15... clearly is not the point of minimum. Also Arny's alternative approach must be viewed with suspicion -- depending on his application, we don't know. If his function is continous and *if* failure of FindMinimum can be interpreted as "there is no minimum in the (open) interval" then he just may check for the boundary values. (Possibly the case might be justifiable, if Arny's functions are Polynomials of degree 2, where the first guess of FindMinimum just hits the minimum exactly. Yet then there are better ways to get at it.) Kind regards, Hartmut