Skip to content

SquareWave ​

The square wave: period 1, default range {-1, 1}, value 1 on [0, 1/2) and -1 on [1/2, 1) of each period.

✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram LanguageSquareWave✓
SquareWave(x)1 for x - floor(x) in [0, 1/2), -1 for x - floor(x) in [1/2, 1).
SquareWave({min, max}, x)the square wave rescaled to vary between min and max, unit period.
Typed signatures
TypePackageApplies
(real | vector<real^2>, real?) -> numberanalyticalways

Domain: Elementary functions

Details
  • SquareWave(0) = 1 -- the half-open convention puts the period's left edge in the high half.
  • Default range is {-1, 1}, not {0, 1} -- SquareWave(1/2) = -1.
  • The range form takes the range FIRST, x second -- SquareWave({min, max}, x) -- matching SawtoothWave and TriangleWave.

Examples

Basic #

SquareWave(0) = 1

live ↗
InSquareWave(0)\mathrm{SquareWave}(0)Out11

The high half is half-open, and the default range is {-1, 1}

live ↗
InSquareWave(12)\mathrm{SquareWave}(\frac{1}{2})Out−1-1
live ↗
InSquareWave(−14)\mathrm{SquareWave}(-\frac{1}{4})Out−1-1
Scope #

Rescaled to a {min, max} range

live ↗
InSquareWave([0,10],0)\mathrm{SquareWave}(\bigl\lbrack0, 10\bigr\rbrack, 0)Out1010

The branch decision is certified numerically even though the output is a plain constant

live ↗
InSquareWave(−π)\mathrm{SquareWave}(-π)Out−1-1

Known value · f = Frac(-π) = 4 - π > 1/2, so the second half

Properties #

Period 1

live ↗
InSquareWave(14)=SquareWave(214)\mathrm{SquareWave}(\frac{1}{4})=\mathrm{SquareWave}(2\frac{1}{4})OutTrue\mathrm{True}
Possible issues #

SquareWave(1) = SquareWave(0) = 1, by our own period-1 convention

live ↗
InSquareWave(1)\mathrm{SquareWave}(1)Out11
About
Examples7
Checked againstWolfram Language 7 agree
CrosswalkWolfram Language