MathGroup Archive 2002

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

Search the Archive

Re: Functions in Mathematica

  • To: mathgroup at smc.vnet.net
  • Subject: [mg33694] Re: Functions in Mathematica
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Tue, 9 Apr 2002 01:01:55 -0400 (EDT)
  • Organization: Universitaet Leipzig
  • References: <a8m2eo$o9d$1@smc.vnet.net>
  • Reply-to: kuska at informatik.uni-leipzig.de
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

> 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)

Plot[UnitStep[x + 2] - UnitStep[x - 2], {x, -4, 4}]

>                 = 0 otherwise
> 
>  2)   Triange
>             f(x) = x for -1<x<0
>                  = 1-|x] for 0<x<1

Plot[Which[
             x < -1 || x > 1, 0,
            x < 0, 1 + x,
            x > 0, 1 - x], {x, -4, 4}]

> 
>  3)  A suare wave with specific period and width

SquareWave[x_?NumericQ, w_?NumericQ, period_?NumericQ] :=
  Block[{xi},
    xi = Mod[x, period];
    UnitStep[xi + w] - UnitStep[xi - w]
    ]

Plot[SquareWave[x, 1/2, 2], {x, -4, 4}]


Regards
  Jens


  • Prev by Date: Re: Optional
  • Next by Date: Re: HTMLSave
  • Previous by thread: Re: Functions in Mathematica
  • Next by thread: Re: help!! Clueless on how to proceed...