Re: FindMinimum[Print[]]

• To: mathgroup at smc.vnet.net
• Subject: [mg86976] Re: FindMinimum[Print[]]
• From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
• Date: Fri, 28 Mar 2008 03:13:28 -0500 (EST)
• Organization: The Open University, Milton Keynes, UK
• References: <fsg6o2\$j61\$1@smc.vnet.net>

```MichaÃ«l Cadilhac wrote:

>   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.

The option StepMonitor is what you are looking for.

In[1]:= FindMinimum[Exp[x] + 1/x, {x, 1},
StepMonitor :> Print["Step to x = ", x]]

During evaluation of In[1]:= Step to x = 0.788886

During evaluation of In[1]:= Step to x = 0.677316

During evaluation of In[1]:= Step to x = 0.706578

During evaluation of In[1]:= Step to x = 0.703587

During evaluation of In[1]:= Step to x = 0.703467

During evaluation of In[1]:= Step to x = 0.703467

Out[1]= {3.44228, {x -> 0.703467}}

In[2]:= 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}, StepMonitor :> Print["Step to x = ", x]]

During evaluation of In[2]:= Step to x = 0.362425

During evaluation of In[2]:= Step to x = 0.362425

During evaluation of In[2]:= Step to x = 0.362159

During evaluation of In[2]:= Step to x = 0.362151

Out[4]= {16.8343, {x -> 0.362151}}

HTH,
--
Jean-Marc

```

• Prev by Date: Re: symbolic evaluation
• Next by Date: Re: Convert Array to Simple List