Re: Functions in Mathematica
- To: mathgroup at smc.vnet.net
- Subject: [mg33704] Re: [mg33672] Functions in Mathematica
- From: BobHanlon at aol.com
- Date: Mon, 8 Apr 2002 03:04:36 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
In a message dated 4/6/02 1:59:50 AM, ravi_banyal at yahoo.com writes: >Can anyone please tell me how we define and Plot functions >of the following types in mathematica. >e.g. > > 1) Box function with amplitude c > f(x)= C for -2<x<2 (c is constant) > = 0 otherwise > > 2) Triange > f(x) = x for -1<x<0 > = 1-|x] for 0<x<1 > > 3) A suare wave with specific period and width > Needs["Graphics`Colors`"]; box[x_, width_:1] := UnitStep[x+width/2]- UnitStep[x-width/2]; triangle[x_, width_:1] := (1+2x/width)*UnitStep[x+width/2]- 4x/width*UnitStep[x]- (1-2x/width)*UnitStep[x-width/2]; squareWave[x_, period_:1, width_:(1/2)] := box[Mod[x, period], 2*width] /; 0< width <= period; Plot[{box[x],2*box[x,2],box[x+.6,2]/2}, {x,-2,2}, PlotStyle->{Red,Blue,Green}]; Plot[{triangle[x], 2*triangle[x,2], .5*triangle[x+.6,2]}, {x,-2,2}, PlotStyle->{Red,Blue,Green}, PlotRange->All]; Plot[squareWave[x+.5,1.5,1], {x,-3.01,3.01}, PlotStyle->{AbsoluteThickness[2],Red}, AspectRatio->Automatic, AxesOrigin->{-3.25,0}, ImageSize->400]; Bob Hanlon Chantilly, VA USA