I'm trying to make a function that goes up two and then down two (kind of like sin(x) but without the curves). I keep drawing a blank on what I can do to even create this functions as I haven't done this type of work in a long time. Maybe theres some piecewise function that can be defined but i'm drawing a blank
Functions that go up two and then down two
84 Views Asked by user195720 https://math.techqa.club/user/user195720/detail AtThere are 3 best solutions below
On
It sounds like you are describing something called a Triangle Wave. There are several different ways to write it. One of the easiest to describe would be using piecewise defined using the fractional part of $x$ (defined as $x - \lfloor x \rfloor$)
Other possible patterns include square waves and sawtooth waves, depending on what it is you want.
Play around with the fractional part of $x$ and horizontal and vertical stretch and vertical shifts, as well as its negative to get a triangle wave that fits your exact image in your mind.

image taken from wikipedia
On
It sounds like you're looking for a Square Wave. The simplest definition would probably be $$f(x) = \textrm{sgn}(\sin x)$$ Where sgn$(x)$ is the sign function. Technically, this equals $0$ when $x=0$, so you may prefer the piecewise $$f(x) = \left\{ \begin{array}{lr} 1 & : \sin x \ge 0 \\ -1 & : \sin x < 0 \end{array} \right.$$ If you don't like either of those, or want to figure out more, you could look into Fourier Series, which can define a square wave in terms of sine waves without any piecewise parts, and are generally just cool.
I feel like you are missing some details in your question, but you could always do something like $$f(x) = \begin{cases} 2 & x\in [2n,2n+1) \\ -2 & x\in [2n+1,2n) \end{cases} $$
for all $n \in \Bbb{Z}$. Equivalently, you could take the Fourier Transform of $$g(x) = \begin{cases} 2 & x\in [0,1) \\ -2 & x\in [-1,0) \end{cases} $$