MathGroup Archive 2013

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

Search the Archive

Re: FindRoot

  • To: mathgroup at
  • Subject: [mg131641] Re: FindRoot
  • From: Bill Rowe <readnews at>
  • Date: Sun, 15 Sep 2013 07:06:46 -0400 (EDT)
  • Delivered-to:
  • Delivered-to:
  • Delivered-to:
  • Delivered-to:

On 9/14/13 at 6:03 AM, bruce.colletti at 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

>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


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


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