MathGroup Archive 2002

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

Search the Archive

Re: Define a function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg34617] Re: Define a function
  • From: "Steve Durbin" <steved at vale.demon.co.uk>
  • Date: Wed, 29 May 2002 02:47:02 -0400 (EDT)
  • References: <acshar$ke2$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

"Michael Popp" <popp.michael at gmx.at> wrote in message
news:acshar$ke2$1 at smc.vnet.net...
> Hello
>
> I want to define a function in Mathematica. But just f[x_]:=...  does not
> work, because I have to define different functions for different ranges of
> the variable x.
> For example:
>
> x < 10:           f(x) = 0
> 10 < x < 20:  f(x) = x
> 20 < x:          f(x) = x/2
>
> How to do this?


Michael,

See the Mathematica help under "Domain" (section 2.3.5). Here's the specific
solution to your example - the /; gives the domain for that part of the
function.

f[x_] := 0 /; x < 10
f[x_] := x /; 10 <= x <= 20
f[x_] := x/2 /; x > 20


 Cheers,
--
Steve Durbin | Look! Minimalism comes to ASCII art!
             |                                           .





  • Prev by Date: RE: help with mathematica problem
  • Next by Date: RE: Define a function
  • Previous by thread: RE: Define a function
  • Next by thread: RE: Define a function