MathGroup Archive 2013

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

Search the Archive

Re: FindRoot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg131641] Re: FindRoot
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Sun, 15 Sep 2013 07:06:46 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-outx@smc.vnet.net
  • Delivered-to: mathgroup-newsendx@smc.vnet.net

On 9/14/13 at 6:03 AM, bruce.colletti at gmail.com wrote:

>Re 9.0.1 under Windows 7.

>The code below is extracted from another source.

>Part I below returns 289 even though n is never given a value.  Why
>does the module return a value and in particular, what does 289
>mean?

>Part II doesn't return a value (as expected).  I don't see why Part
>I returns a value but not Part II.

Module has the following structure

Module[localVariableList, expr1;expr2;...]

Assuming Return is not used in one of the portions of the
compound expression, then Mathematica returns whatever the last
portion of the compound expression evaluates to. That is

expr1;expr2;expr3

Returns result from expr3

Now, for your Part 1, the last portion of the compound
expression was

A[[m,n]] = something

So, Mathematica evaluated something, assigned that result to
A[[m,n]] and returned that result. That is anytime you use Set,
the result returned is the rhs. For example;

In[1]:= a = ConstantArray["", {3, 3}];
a[[2, 3]] = 10

Out[2]= 10

which is why your Part 1 returned a value. Perhaps you wanted to
return the array you defined in this version. If so, simply make
the last portion of the compound expression A. i.e.,

Module[localVaralbieList, expr;expr;A]

As for Part II, the last expression being evaluated was

SurvivalFunction[...]

which was returned. It did not reduce to a value since the local
variable n in your Part II was not given a value. Give the local
variable n a value before the SurvivalFunction call and you will
get a value returned by Part II.





  • Prev by Date: constrained FindFit is extremely slow?
  • Next by Date: Re: ReplacePart
  • Previous by thread: Re: FindRoot
  • Next by thread: Re: FindRoot