Is it possible to set the following function f[a]
, where a
can be any real number?
f(α)={1if 2πn<α<π(2n+1)2if π(2n+1)≤α≤2π(n+1), n∈Z
The issue here is n
which I want to be substituted consecutively by an integer in order to produce propriate continuous conditions. I guess, it is not the case where Assumptions
should be used as my attempt underneath doesn't work.
f[a_] := \[Piecewise] {
{1, 2 \[Pi]n < a && a < \[Pi] (2 n + 1)},
{2, \[Pi] (2 n + 1) <= a && a <= 2 \[Pi] (n + 1)}
}, Assumptions -> n \[Element] Integers
Thanks.
Answer
Here's one way to make your function periodic:
f[t_] := Which[0 <= t < Pi, 1, Pi <= t < 2 Pi, 2, t < 0, f[t + 2 Pi], t > 2 Pi, f[t - 2 Pi]]
For example:
Plot[f[t], {t, -10, 10}]
This method works well for any function you care to use (not just square waves). For instance, f[t] can be linear in one half and quadratic in the second half:
f[t_] := Which[0 <= t < Pi, t, Pi <= t < 2 Pi, t^2, t < 0, f[t + 2 Pi], t > 2 Pi, f[t - 2 Pi]];
Plot[f[t], {t, -10, 10}]
Comments
Post a Comment