Is it possible in Mathematica to plot an even piecewise function like:

$ f(x) = \begin{cases} 3t , 0 \le t \le \frac{\pi}{2} \\ 3t + 6 , \frac{\pi}{2} \le t \le \pi \end{cases}$

which has a period of $2\pi$ . I can plot the function as is like so:

Plot[Piecewise[{{3t, 0 <= t <= π/2}, {3t + 6, π/2 <= t <= π}}], {t, 0, π}]

but I can't seem to get it to repeat or show evenly.

  • 1
    $\begingroup$ You might be interested in this. $\endgroup$ – J. M.'s ennui Oct 23 '12 at 10:25

The concepts of "even" and "periodic" relate to the action of the one-dimensional analogs of wallpaper groups. "Even" means that the function is invariant under reflection about the origin, $t \to -t$, and "periodic" means it is invariant under translation by some period $p$, $t \to t+p$.

The function $f$ in the question has been declared over a fundamental domain, in this case the interval from $0$ to $\pi$. To extend it to a function of the reals, for each $t$ not in this domain we need to find a group element $g$ (generated by the reflection and translation) for which the application of $g$ to $t$ yields a number $t^{(g)}$ in the fundamental domain. We then define $f(t)$ to equal $f(t^{(g)})$.

Although this may sound abstract, it translates to a highly general, efficient, almost mindless computational method. For one-dimensional groups, we can figure out $t^{(g)}$ by means of the Mod function (to implement the translation) and the Abs function (to implement the reflection). It is convenient first to translate $t$ into a domain that is as close to the origin as possible: do this by offsetting Mod by half the period, as in Mod[t, 2 Pi, -Pi]. The result now lies in the symmetrical interval $[-\pi, \pi]$ around $0$. Taking the absolute value assures the result is positive, where $f$ can be applied. Whence, after defining f as in the question, merely declare its extension g by following this recipe:

f[t_] := Piecewise[{{3 t, 0 <= t <= Pi/2}, {3 t + 6, Pi/2 <= t < Pi}}, Null];
g[t_] := f[Abs[Mod[t, 2 Pi, -Pi]]];
Plot[{g[t], f[t]}, {t, -10, 10}, PlotStyle -> {Thick, Thick}]

Plot of g and f

Visually, it is clear that $g$ (the blue graph) is even and periodic and agrees with $f$ (the red graph) on the fundamental domain $[0, \pi)$ where $f$ is defined.

  • $\begingroup$ Deleted my answer. It wasn't periodic at all! :D $\endgroup$ – Dr. belisarius Oct 23 '12 at 14:53

You could use a Mod function to sample the area you have the function defined over at other parts of the $x$-axis if that's what you're aiming for.

f[t_] := Piecewise[{{3 t, 0 <= t <= π/2}, {3 t + 6, π/2 <= t <= π}}]
Plot[f[Mod[t, π]], {t, -π, 2 π}]

plot of function

  • $\begingroup$ I notice that your avatar is changing with your IP address. If you set an email address in your profile it will remain constant. It doesn't have to be a real one, and in fact you can try several until you find one that creates an avatar pattern that you like. If you use a fake one it's better to make it obviously fake so that an admin doesn't try to use it to contact you. $\endgroup$ – Mr.Wizard Oct 23 '12 at 12:08
  • 2
    $\begingroup$ This graph does not depict an "even ... function ... which has period of $2\pi$": it is not even and its period is only $\pi$. $\endgroup$ – whuber Oct 23 '12 at 14:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.