MathGroup Archive 1997

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

Search the Archive

Re: How to use Needs inside While?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg6324] Re: [mg6302] How to use Needs inside While?
  • From: Allan Hayes <hay at haystack.demon.co.uk>
  • Date: Sat, 8 Mar 1997 23:26:47 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

sergio at scisun.sci.ccny.cuny.edu (Sergio Rojas)
[mg6302] How to use Needs inside While?
sends the problem copied below the line ************.

Sergio:
It looks like the problem arises because the symbols in an  
expression are created *before* evaluation. So, with Needs inside  
the loop, NonlinearFit is created as Global`NonlinearFit not  
Statistics`NonlinearFit. One possible way out might be to replace  
NonlinearFit in the body of the loop with Statistics`NonlinearFit.

Allan Hayes
hay at haystack.demon.co.uk
http://www.haystack.demon.co.uk

*******************************************************
Hello fellows,

   If I put the expression Needs["Statistics`NonlinearFit`"] inside
a While loop, the function NonlinearFit does not work and Mathematica
output the error:

NonlinearFit::shdw:
   Warning: Symbol NonlinearFit appears in multiple contexts
    {Statistics`NonlinearFit`, Global`}; definitions in context
    Statistics`NonlinearFit` may shadow or be shadowed by other  
definitions.

   If the statement is outside the loop,  no error is displayed and
NonlinearFit works fine.

   How to use Needs["..."] inside any loop ?

Example:

 Needs["Statistics`NonlinearFit`"];(* here it works *)

answer = 0;
While[ answer == 0,
(* Needs["Statistics`NonlinearFit`"]; (* here it does not work *)
    Clear[a,b,c,d,abcd];
    xmin = Input[" Enter xmin (try -4.)"];
    xmax = Input[" Enter xmax (try  0.)"];
    incr = Input[" Enter the increment (try 0.1)"];
    data = Table[{x, 1.5*Exp[1.5*x] + 1.5*Sin[1.5*x]}, {x, xmin,  
xmax, incr}];
    abcd = NonlinearFit[data, a*Exp[b*x] + c*Sin[d*x], x, {a,b,c,d}];
              a = a /. abcd ;
              b = b /. abcd ;
              c = c /. abcd ;
              d = d /. abcd ;
         Print[" a= ", a," ; b= ",b," ; c= ",c," ; d= ",d];
  answer = Input[" To try other interval, enter 0 and hit RETURN "]]

Sergio

E-mail: sergio at scisun.sci.ccny.cuny.edu




  • Prev by Date: Re: Version 3
  • Next by Date: Re: Re: y=f(t) vs t=f(y)
  • Previous by thread: How to use Needs inside While?
  • Next by thread: Displaying Rotated Text on a Macintosh or Sun