MathGroup Archive 1997

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

Search the Archive

Want to use Module

  • To: mathgroup at smc.vnet.net
  • Subject: [mg9773] Want to use Module
  • From: Ersek_Ted%PAX1A at mr.nawcad.navy.mil
  • Date: Tue, 25 Nov 1997 00:07:24 -0500
  • Sender: owner-wri-mathgroup at wolfram.com

I need to write a function like  foo[x]  below.

In[1]:=
y[x_]:=x Exp[x]+2;

In[2]:=
foo[x_]/;(temp=y[x]; temp<100):= 2/(3+temp)

In[3]:=
foo[2]

Out[3]=
2/(5 + 2*E^2)

In[4]:=
foo[20]

Out[4]=
foo[20]

In[5]:=
Clear[s];
foo[s]

Out[5]=
foo[s]

Notice foo[x] is only defined when (y[x]<100). (y[20]<100)->False,  so
foo[20] is returned unevaluated. (y[s]<100)  is not defined,  so foo[s]
is returned unevaluated.

I used (temp=y[x]) so I wouldn't have to evaluate y[x] twice. How can I
do this with (temp) inside a Module, so it is local to (foo[x])?

     Thanks

     Ted Ersek
     ersek_ted%pax1a at mr.nawcad.navy.mil



  • Prev by Date: ListPlot command
  • Next by Date: Re: ListPlot command
  • Previous by thread: Re: Boolean, Binary logic
  • Next by thread: Re: Want to use Module