MathGroup Archive 2002

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

Search the Archive

RE: Is it possible to access internal variables? [CompoundExpress ion]

  • To: mathgroup at smc.vnet.net
  • Subject: [mg34811] RE: Is it possible to access internal variables? [CompoundExpress ion]
  • From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
  • Date: Sat, 8 Jun 2002 05:21:19 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

> -----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: [mg34811] 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


  • Prev by Date: RE: Problem with hypergeometric function
  • Next by Date: Re: Use of ShowProgress Option output
  • Previous by thread: Sorting with absolute precision
  • Next by thread: how can I solve this with mathematica?