How do you plot a graph where $y$ increases in short bursts and not linearly?

51 Views Asked by At

I am wondering if it's possible to plot this sort of graph with one equation. enter image description here

Note: the application of what I am doing is for video animation, but I am just asking for the mathematical explanation; software has nothing to do with this.

For context, $y$-axis is rotation in degrees, and $x$-axis is time in seconds. The item rotates 30 degrees every half second. I wonder if it's possible to plot a graph more like the red line, where the rotation ($y$) will accelerate and decelerate to almost a stop at every 30 degrees.

Is there a name for a graph like this? I don't think I would call it an oscillation or a saw-tooth or something.

3

There are 3 best solutions below

2
On BEST ANSWER

Hint: You can use a function like $$ y=ax-b|\sin (cx+d)| $$

adjusting the constants $a,b,c,d$.

0
On

You could make each segment a quadratic: quadratic functions passing through $(0,0)$ and $(1,m)$ are of the form $f(x)=mx+ax(x-1)$ (assuming the $x$ steps are $1$). You want $a>0$ to get that shape for a given segment. Then you can extend it to "follow the line" by defining $g(x)=\lfloor x \rfloor + f(x-\lfloor x \rfloor)$.

0
On

I'm sure there are many ways of doing this, here's one.

Suppose that the "first bit" of your graph is $y=f(x)$. For example, the one you have drawn looks a bit like $y=cx^2$ for some constant $c$. Suppose that the "first bit" goes from $x=0$ to $x=a$ (so in your example $a=\frac12$). And suppose that the gradient of the grey line in your diagram is $m$. Then the whole graph is given by $$y=f\Bigl(x-a\Bigl\lfloor\frac xa\Bigr\rfloor\Bigr)+ma\Bigl\lfloor\frac xa\Bigr\rfloor\ ,$$ where $\lfloor\cdots\rfloor$ means "round to the next integer downwards", possibly implemented as floor or truncate or trunc, depending what software you are using.