# Plotting a piecewise function in Mathematica 10.0

How to I plot the following function in one diagram: from $0$ to $\frac{\pi}{2}$ the function has to equal $\left|\sin\left(x\right)\right|$ and from $\frac{\pi}{2}$ the function $\exp\left(-\frac{x}{220}\right)$ starts untill that function hits the following bump of $\left|\sin\left(x\right)\right|$ and when that happends the function $\left|\sin\left(x\right)\right|$ starts again and so on.

• – Jason B. Feb 5 '18 at 16:50
• @JasonB. I saw those links before, but I don't get it because I have the property that the two functions hit/cross eachother – Jan Feb 5 '18 at 16:51
• Your question isn't really clear as written. Are you looking for something like this? – Jason B. Feb 5 '18 at 17:18
• @JasonB. This is maybe better: $$\begin{cases} y=\left|\sin\left(x\right)\right|\space\space\space\space\space\space\space\space\text{when}\space0\le x<\frac{\pi}{2}\\ \\ \color{red}{y=\exp\left(-\frac{x}{220}\right)\space\space\space\text{when}\space\frac{\pi}{2}\le x<\left(\left|\sin\left(x\right)\right|=\exp\left(-\frac{x}{220}\right)\space\Longleftrightarrow\space x=\dots\right)} \end{cases}$$ For the red part: when you solve $x$ it has to be between the following boundaries: $$\frac{\pi}{2}<x<\frac{3\pi}{2}$$ And then then it starts again. So it is periodic in $x$. – Jan Feb 5 '18 at 17:26
• You can see here Plot[{Exp[-x/220], Sin[x]}, {x, 0, 30}, MeshFunctions -> {(Exp[-#1/220] - Sin[#1]) & }, Mesh -> {{0}}, MeshStyle -> Directive[Red, PointSize[Large]] ] that your two functions intersect twice per period. Do you mean for the discontinuities in the piecewise function to occur at these points? Could you add a graphic to show what you mean? Also, add the expanded equation to the post, rather than as a comment – Jason B. Feb 5 '18 at 17:32

Perhaps this is what you are looking for.

f[x_] :=
With[{u = Mod[x, 3 π/2]},
Piecewise[{{Abs[Sin[u]], 0 <= u < π/2}, {E^(-u/229), π/2 < u <= 3 π}}]]

Plot[f[x], {x, 0, 3 π}]


K = 20;

• You could do this a bit more succinctly as Plot[ Min[{ Abs[ Sin[x]], Exp[-x/220]}], {x,0,20}] – Jason B. Feb 5 '18 at 18:27