MathGroup Archive 2005

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

Search the Archive

Re: Condition for pure functions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg59805] Re: [mg59797] Condition for pure functions
  • From: Pratik Desai <pdesai1 at umbc.edu>
  • Date: Mon, 22 Aug 2005 02:48:22 -0400 (EDT)
  • References: <200508210751.DAA26612@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Wonseok Shin wrote:

>Hello everyone,
>
>Suppose that f[x] is defined as:
>
>f[x_ /; x > 0] := Sin[x];
>f[x_ /; x <= 0] := Tan[x];
>
>How can transform the above definition into a pure function?
>
>I know
>
>f = Which[# > 0, Sin[#], # <= 0, Tan[#]] &
>
>is a one solution.  But is there any clever way to use Condition (/;)
>instead of Which[...] ?
>
>  
>
I might be wrong but if you have 5.1.1 and above why not use piecewise,

f[x_] = Piecewise[{{Tan[x], x <= 0}, {Sin[x], x > 0}}] // PiecewiseExpand
Plot[f[x], {x, -10, 10}]

Or use UnitStep

f1[x_] = Tan[x]*UnitStep[-x] + Sin[x]*UnitStep[x]
Plot[f1[x], {x, -10, 10}]


Hope this helps

Best regards

Pratik

-- 
Pratik Desai
Graduate Student
UMBC
Department of Mechanical Engineering
Phone: 410 455 8134



  • Prev by Date: Re: adjust magnification of notebook to a value other than one of the predefined values?
  • Next by Date: Re: ever gotten SVG Export to work?
  • Previous by thread: Condition for pure functions
  • Next by thread: Re: Condition for pure functions