SquareWave[x]
gives a square wave that alternates between
and
with unit period.
SquareWave[{y1,y2},x]
gives a square wave that alternates between y1 and y2 with unit period.
SquareWave
SquareWave[x]
gives a square wave that alternates between
and
with unit period.
SquareWave[{y1,y2},x]
gives a square wave that alternates between y1 and y2 with unit period.
Details
- SquareWave[{min,max},x] has value max for 0<x<1/2.
- SquareWave automatically threads over lists. »
Examples
open all close allBasic Examples (3)
SquareWave[0.2]Plot over a subset of the reals:
Plot[SquareWave[x], {x, -3, 3}]SquareWave is a piecewise function over finite domains:
PiecewiseExpand[SquareWave[x], -1 ≤ x ≤ 1]Scope (34)
Numerical Evaluation (5)
SquareWave[-1]SquareWave[1 / 4]SquareWave[{0, 2}, 1.6]SquareWave[x] always returns an exact result:
SquareWave[.123]SquareWave[{min,max},x] generally tracks the precision of {min,max}:
SquareWave[{1`4, 2`8}, 1 / 2]Evaluate efficiently at high precision:
SquareWave[247.5`100]//TimingSquareWave[27`10000];//TimingSquareWave threads over lists in the last argument:
SquareWave[{0.4, 1.2, 3.6}]SquareWave[{0, 5}, {0.4, 1.2, 3.6}]Compute the elementwise values of an array using automatic threading:
SquareWave[{{1 / 4, -1 / 5}, {0, 1 / 5}}]Or compute the matrix SquareWave function using MatrixFunction:
MatrixFunction[SquareWave, {{1 / 4, -1 / 5}, {0, 1 / 5}}]Specific Values (4)
SquareWave[0]Table[SquareWave[x], {x, 0, 2, 2 / 3}]FunctionExpand[SquareWave[x], x∈Reals]PiecewiseExpand[SquareWave[x], 0 < x < 1]Find a value of x for which the SquareWave[{2,-3},x]=2:
xval = x /. FindRoot[SquareWave[{2, -3}, x] == 2, {x, 0.6}]Plot[SquareWave[{2, -3}, x], {x, 0, 2}, Epilog -> Style[Point[{xval, SquareWave[{2, -3}, xval]}], PointSize[Large], Red], ExclusionsStyle -> Dotted]Visualization (4)
Plot the SquareWave function:
Plot[SquareWave[x], {x, -3, 3}, Filling -> Axis]Visualize scaled SquareWave functions:
Plot[#, {x, 0, 4}, PlotLabel -> #, LabelStyle -> 10, ImageSize -> 150]& /@ {SquareWave[x], SquareWave[x / 2], SquareWave[2x]}Visualize SquareWave functions with different maximum and minimum values:
Plot[{SquareWave[x], SquareWave[{-1 / 2, 1 / 2}, x], SquareWave[{0, 2}, x]}, {x, -2, 2}, PlotLegends -> "Expressions"]Plot SquareWave in three dimensions:
Plot3D[SquareWave[x + y], {x, -1, 1}, {y, -1, 1}, ColorFunction -> "SouthwestColors"]Function Properties (11)
Function domain of SquareWave:
FunctionDomain[SquareWave[{a, b}, x], {x, a, b}]It is restricted to real inputs:
FunctionDomain[SquareWave[{a, b}, x], {x, a, b}, Complexes]Function range of SquareWave[x]:
FunctionRange[SquareWave[x], x, y]SquareWave is periodic with period 1:
FunctionPeriod[SquareWave[x], x]SquareWave is an odd function:
FullSimplify[SquareWave[x] == -SquareWave[-x], x∈Reals]The area under one period is zero:
Integrate[SquareWave[x], {x, 0, 1}]SquareWave is not an analytic function:
FunctionAnalytic[SquareWave[x], x]It has both singularities and discontinuities on the integers:
FunctionSingularities[SquareWave[x], x]FunctionDiscontinuities[SquareWave[x], x]SquareWave[x] is neither nondecreasing nor nonincreasing:
FunctionMonotonicity[SquareWave[x], x]SquareWave is not injective:
FunctionInjective[SquareWave[{a, b}, x], x, Assumptions -> a < b]Plot[{SquareWave[x], 1}, {x, -7, 7}]SquareWave[x] is not surjective:
FunctionSurjective[SquareWave[x], x]Plot[{SquareWave[x], -.5}, {x, -5, 5}]SquareWave[x] is neither non-negative nor non-positive:
FunctionSign[SquareWave[x], x]SquareWave is neither convex nor concave:
FunctionConvexity[SquareWave[{a, b}, x], x, Assumptions -> a < b]Differentiation and Integration (5)
First derivative with respect to
:
D[SquareWave[x], x]Derivative of the two-argument form with respect to
:
D[SquareWave[{a, b}, x], x]If a==b, SquareWave[{a,b},x] is constant and its derivatives are zero everywhere:
Table[D[SquareWave[{a, a}, x], {x, k}], {k, 3}]Compute the indefinite integral using Integrate:
Integrate[SquareWave[x], x]Verify the anti-derivative away from the singular points:
FullSimplify[D[%, x] == SquareWave[x], x∈Reals && x∉ℤ]Integrate[SquareWave[x]RealSign[x], x]Integrate[ x SquareWave[x^2], {x, 1, 3}]//FullSimplifySeries Expansions (5)
FourierSeries[SquareWave[x], x, 3]Since SquareWave is odd, FourierTrigSeries gives a simpler result:
FourierTrigSeries[SquareWave[x], x, 3]The two results are equivalent:
Simplify[% == %%]FourierCosSeries of a scaled SquareWave:
FourierCosSeries[SquareWave[(x/π)], x, 4]Taylor series at a smooth point:
Series[SawtoothWave[x], {x, 1 / 2, 3}, Assumptions -> x < 1]//NormalSeries expansion at a singular point:
Series[SawtoothWave[x], {x, 0, 3}, Assumptions -> x < 1]Taylor expansion at a generic point:
Series[TriangleWave[x], {x, x0, 2}]//Normal// FullSimplifyApplications (2)
Play[SquareWave[440 x], {x, 0, 1}]Compute the Fourier decomposition:
FourierSinCoefficient[SquareWave[x], x, n, FourierParameters -> {1, 2Pi}]Get the ninth-order partial sum:
FourierSinSeries[SquareWave[x], x, 9, FourierParameters -> {1, 2Pi}]At the points of discontinuity, the Gibbs phenomenon of overshooting is observed:
Plot[{SquareWave[x], %}, {x, 0, 2}, ExclusionsStyle -> Dashed]Properties & Relations (4)
Use FunctionExpand to expand SquareWave in terms of elementary functions:
FunctionExpand[SquareWave[x], x∈Reals]Use PiecewiseExpand to obtain a piecewise representation:
PiecewiseExpand[SquareWave[x], 0 < x < 2]Plot[SquareWave[x]Sinc[2Pi x], {x, 0, 1}, Filling -> Axis]Integrate[SquareWave[x]Sinc[2Pi x], {x, 0, 1}]N[%, 20]Compute a finite number of Fourier coefficients:
Table[FourierCoefficient[SquareWave[x / (2Pi)], x, n], {n, 1, 10}]FindSequenceFunction[%, n]Use a FourierCoefficient directly:
FourierCoefficient[SquareWave[x / (2Pi)], x, n]Verify the consistency of formulas:
Simplify[%% - %, n∈Integers && n > 0]Possible Issues (2)
SquareWave is only defined on real numbers:
SquareWave[1.0 + 0.5 I]SquareWave[x] is upper semicontinuous but not lower semicontinuous at the origin:
{Underscript[, x -> 0]SquareWave[x] ≤ SquareWave[0], Underscript[, x -> 0]SquareWave[x] ≥ SquareWave[0]}This differs from TriangleWave[x], which is both upper and lower semicontinuous, and thus continuous:
Underscript[, x -> 0]TriangleWave[x] ≤ TriangleWave[0] && Underscript[, x -> 0]TriangleWave[x] ≥ TriangleWave[0]As well as SawtoothWave[x], which is only lower semicontinuous:
{Underscript[, x -> 0]SawtoothWave[x] ≤ SawtoothWave[0], Underscript[, x -> 0]SawtoothWave[x] ≥ SawtoothWave[0]}Visualize the three functions:
GraphicsRow[Plot[#[x], {x, -1, 1}, IconizedObject[«Plot options»]]& /@ {SquareWave, TriangleWave, SawtoothWave}, ImageSize -> 500]Related Guides
Related Links
History
Text
Wolfram Research (2008), SquareWave, Wolfram Language function, https://reference.wolfram.com/language/ref/SquareWave.html.
CMS
Wolfram Language. 2008. "SquareWave." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/SquareWave.html.
APA
Wolfram Language. (2008). SquareWave. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/SquareWave.html
BibTeX
@misc{reference.wolfram_2026_squarewave, author="Wolfram Research", title="{SquareWave}", year="2008", howpublished="\url{https://reference.wolfram.com/language/ref/SquareWave.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_squarewave, organization={Wolfram Research}, title={SquareWave}, year={2008}, url={https://reference.wolfram.com/language/ref/SquareWave.html}, note=[Accessed: 13-June-2026]}