MathGroup Archive 2011

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

Search the Archive

Re: NMinimize problem: fct minimized uses FindRoot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg123639] Re: NMinimize problem: fct minimized uses FindRoot
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Wed, 14 Dec 2011 06:00:01 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <201112101227.HAA19219@smc.vnet.net>
  • Reply-to: drmajorbob at yahoo.com

There's a large gap between "explained and justified" versus "worth the  
trouble" or even "sensible".

Do not use Return. It isn't worth the spit you'll need to polish it.

Bobby

On Tue, 13 Dec 2011 04:39:04 -0600, Andrzej Kozlowski <akoz at mimuw.edu.pl>  
wrote:

>
> On 12 Dec 2011, at 12:43, Oleksandr Rasputinov wrote:
>
>> For example, the erroneous usage:
>>
>> Block[{a = 1, b = 2}, Return[a]; Return[b]]
>>
>> gives:
>>
>> Return[1]
>>
>> but a correct usage:
>>
>> Do[Block[{a = 1, b = 2}, Return[a]; Return[b]], {1}]
>>
>> gives (because of the enclosing Do):
>>
>> 1
>
> This is not quite the whole story. For example, while the above use of  
> Return in Block does not work, this one (in a function call) does:
>
> f[] := Block[{a = 1, b = 2}, Return[a]; Return[b]]
>
> f[]
>
> 1
>
> Moreover, if you replace the Do loop in your example with a While loop,  
> you will get:
>
> n = 1; While[n < 10, Block[{a = 1, b = 2}, Return[a]; Return[b]]]
>
> Return[1]
>
> All of this is purposeful design and can be explained and justified but  
> I don't think it's worth the bother since Mathematica has far superior  
> means of flow control than this clumsy and arcane construct.
>
> Andrzej
>
>


-- 
DrMajorBob at yahoo.com



  • Prev by Date: Re: How to run ".nb" file always in dos command line
  • Next by Date: Function calling another function that uses NSolve - can't get this
  • Previous by thread: Re: NMinimize problem: fct minimized uses FindRoot
  • Next by thread: Re: NMinimize problem: fct minimized uses FindRoot