Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

Re: FindMinimum[Print[]]

  • To: mathgroup at smc.vnet.net
  • Subject: [mg86980] Re: FindMinimum[Print[]]
  • From: David Bailey <dave at Remove_Thisdbailey.co.uk>
  • Date: Fri, 28 Mar 2008 03:14:13 -0500 (EST)
  • References: <fsg6o2$j61$1@smc.vnet.net>

Michaël Cadilhac wrote:
>   Hello list !
> 
>   I'm really new to Mathematica (though I can already say wow), and,
> following the tutorial[1] (which might be quite outdated), one of the
> exercise got me in trouble.
> 
>   The author asks to reformulate the following actions
> 
> m = {{12,      1 + x,  4 - x,  x},
>      {4 - x,   11,     1 + x,  x},
>      {1 + x,   1 - x,  15,     x},
>      {x - 1,   x - 1,  x - 1,  x - 1}};
> expr = Max[Re[Eigenvalues[m]]];
> FindMinimum[expr, {x, 0, 1}]
> 
>   into a more optimized version.  In the course of doing that, I wanted
> to do something like
>     FindMinimum[Print[x]; x^2, {x, 1}],
> hoping to see how is this whole thing is expanded/parsed.  But, despite
> the fact that some articles on that newsgroup used the same form, this
> didn't print the iterations as expected.
> 
>   I wanted to understand how I should write
>     FindMinimum[Max[Eigenvalues[m]], {x, 0, 1}]
> so that the eigenvalues are computed on the fully numerical
> (non-symbolic) matrix.
> 
>   Thanks in advance for any information on that simple matter.
> 
> Footnotes:
> [1]  http://library.wolfram.com/conferences/devconf99/withoff/
> 
> =2D-
>  |   Micha=EBl `Micha' Cadilhac       |  Isn't vi that text editor with    =
>      |
>  |   http://michael.cadilhac.name   |   two modes... One that beeps and    =
>    |
>  |   JID/MSN:                       |     one that corrupts your file?     =
>    |
>  `----  michael.cadilhac at gmail.com  |           -- Dan Jacobson          - =
>  --'
> 
> 
The reason that inserting a Print into the expression to be minimised 
can be found in the help for FindMinimum:

FindMinimum first localizes the values of all variables, then evaluates 
f with the variables being symbolic, and then repeatedly evaluates the 
result numerically.

It is that initial symbolic evaluation that strips out the Print 
command. Although there are ways of avoiding this, the easiest way to 
achieve what you want is to use:

FindMinimum[x^2, {x, 1}, EvaluationMonitor :> Print[x]]

Without giving away the solution to the original exercise, try executing 
the original sequence of operations one step at a time (split into 
separate cells), and look at the intermediate results!

Yes, the only reasonable reaction to Mathematica is Wow!

David Bailey
http://www.dbaileyconsultancy.co.uk


  • Prev by Date: Re: The FinancialData Function
  • Next by Date: Re: Re: Re: smallest fraction
  • Previous by thread: Re: FindMinimum[Print[]]
  • Next by thread: Re: Equi-sized tick labels