Re: Definitions of the functions
- To: mathgroup at smc.vnet.net
- Subject: [mg34975] Re: [mg34963] Definitions of the functions
- From: BobHanlon at aol.com
- Date: Mon, 17 Jun 2002 03:26:50 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
In a message dated 6/16/02 12:29:53 AM, pmg at wp.pl writes:
>How do I define a function that is described by different formulas depending
>of the interval which the argument is given in????
>For example:
>
>y=x for -inf<x<-5
>y=x*x for -5<=x<18
>y=sin x for all the remaining values of x.
>
method 1
Clear[y];
y[x_/;x<-5] := x ;
y[x_/;x<18] := x^2;
y[x_] := Sin[x];
method 2
Clear[y];
y[x_] := x + UnitStep[x+5]*(x^2-x) +
UnitStep[x-18]*(Sin[x]-x^2);
method 3
Clear[y];
y[x_] := Which[
x < -5, x,
x < 18, x^2,
True, Sin[x]];
method 4
Clear[y];
y[x_] := If[x<-5, x, If[x<18, x^2, Sin[x]]];
Bob Hanlon
Chantilly, VA USA