       Re: square wave function

• To: mathgroup at smc.vnet.net
• Subject: [mg31701] Re: square wave function
• From: peter weijnitz <pewei at algonet.se>
• Date: Tue, 27 Nov 2001 02:47:54 -0500 (EST)
• Approved: Steven M. Christensen <steve@smc.vnet.net>, Moderator
• References: <9tlb73\$pep\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```This is a variant:
f[x_] := 1  /; 0 >= x < 1/2
f[x_] := 0 /; 1/2 <=  x < 1
f[x_] := f[x - 1] /; x >=1
f[x_] := f[x + 1] /; x < 0

using conditional definitions it seems to be  flexible thanusing Mod but
maybe it  is not computationally efficient

Peter W

Peter Dimitriou wrote:

> To all who responded last time I posted, thank you, I was able to
> resolve that on my own.
>
> My new Question deals with the following lines of Mathematica code:
>
> Clear[square]
> square[x_] := 1 /; 0<x<1
> square[x_] := -1 /; -1<x<0
>
> Plot[square[x], {x,-1,1}]
>
> This defines and plots a square wave of period 2 between -1 and 1.
> The question is how do I define this for all x (-inf<x<inf, with
> period 2) in Mathematica?  The Only hint I get is to consider using
> the Mod function.  Scratched my head long enough anyone out there
> willing to help?
>
> Peter

```

• Prev by Date: bisection method
• Next by Date: Re: printing in mathematica
• Previous by thread: Re: square wave function
• Next by thread: integral function