# Combine EvenQ and Clip to create a series of pulses

I have a function that produces a single impulse spanning the range [-1,1]:

func1 = Cos[Pi*(Clip[x]/2)]^2 I want to create a second function that produces a series of such pulses, with each pulse centred on an instance of EvenQ[x/3]=True. It feels like it should be simple, but I can't figure it out. This is what I tried:

eventest = If[EvenQ[x/3] = True, 1, 0];
func2 = eventest*func1;
Plot[func2, {x, 0, 20}]


...but as you can see, it doesn't work.

What am I doing wrong?

• Hi @kglr, sadly this doesn't seem to work. it produces an inverted square wave in the range [-1,1] and nothing else. I'm after a series of pulses like the one I have now added to the original post, with each pulse centred on an instance of x/3 is even. Oct 21, 2018 at 13:45
• thank you @Richard
– kglr
Oct 21, 2018 at 14:24

Using the method from this answer (see this as well):

pulse[x_] := Cos[π Clip[Mod[x, 6, -3]]/2]^2

• (will add a plot when I am not using gedanken Mathematica) Oct 21, 2018 at 14:31
• Thanks @J.M. - this works, so will mark as answered; but I do wonder if there is a more general version that would work with more general sequences. For example, what if I wanted a sequence that gave pulses at all x that satisfy TrueQ[truetest] for some arbitrary test on x? Just trying to learn how to drive the machine better! Oct 21, 2018 at 16:03
• I like the idea of gedanken Mathematica, BTW! Hopefully you'll get the machine back soon! :-) Oct 21, 2018 at 16:04
• Boole[] (i.e. the Iverson bracket) is a useful tool for constructing general conditional functions; but, constructing the right conditions to put in it is as much art as science. Oct 21, 2018 at 16:09
• Interesting (and again thank you). I just tried Plot[Boole[OddQ[x]]*Cos[Pi*(Clip[x]/2)]^2, {x, -5, 5}], but it just gives a flat-line zero... This could be tricky! Oct 21, 2018 at 16:16
Plot[Boole[Or @@ (Divisible[{Floor[x + 1], Ceiling[x - 1]}, 6])]
Cos[Pi x / 2]^2, {x, -15, 15}, PlotRange -> {0, 1}] Also

Plot[Boole[And @@ EvenQ[Quotient[Through[{Floor, Ceiling}[x + 1]], 3]]]
Cos[Pi x/2]^2, {x, -15, 15}, PlotRange -> {0, 1}]


same picture

• Maybe change to EvenQ[Round[x/3]]? Oct 21, 2018 at 14:35