y=max⁡(sin⁡x, cos⁡x)y = \max(\sin x,\, \cos x)

Graph of the Function y=max⁡(sin⁡x, cos⁡x)y = \max(\sin x,\, \cos x)

y=max⁡(sin⁡x, cos⁡x)y = \max(\sin x,\, \cos x) selects whichever of the sine and the cosine is larger. Two smooth waves are overlaid and only the upper one is followed, so a corner appears wherever they cross. It is a good place to see what taking a maximum does to a graph.

Which one is on top

The two agree when sin⁡x=cos⁡x\sin x = \cos x, that is tan⁡x=1\tan x = 1, at x=π4+nπx = \dfrac{\pi}{4} + n\pi. Those points are where the roles swap.

IntervalFunction selected
−3π4<x<π4-\dfrac{3\pi}{4} < x < \dfrac{\pi}{4}cos⁡x\cos x
π4<x<5π4\dfrac{\pi}{4} < x < \dfrac{5\pi}{4}sin⁡x\sin x

This repeats every 2π2\pi, so the period is 2π2\pi.

Range

The maximum value is 11, attained twice per period: at x=2nπx = 2n\pi where cos⁡x=1\cos x = 1, and at x=π2+2nπx = \dfrac{\pi}{2} + 2n\pi where sin⁡x=1\sin x = 1. The minimum is the lower of the two crossings, namely −22≈−0.707-\dfrac{\sqrt{2}}{2} \approx -0.707 at x=5π4+2nπx = \dfrac{5\pi}{4} + 2n\pi.

The range is therefore −22≤y≤1-\dfrac{\sqrt{2}}{2} \leq y \leq 1. The value never sinks to −1-1, which both original functions do reach, because whenever one of them is −1-1 the other is 00.

Corners and crests

At a crossing the one-sided slopes disagree.

At x=π4x = \dfrac{\pi}{4}Slope
cos⁡x\cos x coming in from the left−22-\dfrac{\sqrt{2}}{2}
sin⁡x\sin x continuing to the right22\dfrac{\sqrt{2}}{2}

The result is a downward-pointing corner, and the same happens at x=5π4x = \dfrac{5\pi}{4}. The crests, by contrast, are the genuine maxima of whichever function is selected, so they are smooth. Two corners and two smooth crests appear in each period.

In terms of absolute values

Using the formula max⁡(a,b)=a+b+∣a−b∣2\max(a, b) = \dfrac{a + b + |a-b|}{2} the function can be written as follows.

max⁡(sin⁡x, cos⁡x)=22(sin⁡(x+π4)+∣sin⁡(x−π4)∣)\max(\sin x,\, \cos x) = \frac{\sqrt{2}}{2}\left(\sin\left(x+\frac{\pi}{4}\right) + \left|\sin\left(x-\frac{\pi}{4}\right)\right|\right)

This follows by substituting sin⁡x+cos⁡x=2sin⁡(x+π4)\sin x + \cos x = \sqrt{2}\sin\left( x+\dfrac{\pi}{4} \right) and sin⁡x−cos⁡x=2sin⁡(x−π4)\sin x - \cos x = \sqrt{2}\sin\left( x-\dfrac{\pi}{4} \right). The function is thus a smooth sine wave plus the absolute value of another, and the corners come entirely from the second term, inherited from the corners of ∣sin⁡x∣|\sin x|.

What taking a maximum does

A function built with max⁡\max generally fails to be differentiable where its ingredients cross, however smooth those ingredients are. The ramp function max⁡(0,x)\max(0, x) bends at the origin for the same reason, being the case where one ingredient is the constant 00.

Taking a minimum instead traces the lower envelope, and the two are linked as follows.

min⁡(sin⁡x, cos⁡x)=sin⁡x+cos⁡x−max⁡(sin⁡x, cos⁡x)\min(\sin x,\, \cos x) = \sin x + \cos x - \max(\sin x,\, \cos x)

Applications

A circuit that selects the stronger of two signals, or a design in which the tightest of several constraints governs, has a response of this shape. In optimization, minimizing the maximum of several linear expressions is a standard problem, and there too the central issue is how to handle a function with corners1.

  1. Convex optimization, Wikipedia