I am trying to plot the following function:
Where x=(x-floor(x))
This is what I have written in my .tex-file:
\draw[color=blue,smooth] plot({\x-floor(\x)},{\frac{\cos(\frac{\pi}{6})}{ \cos(\frac{\pi}{3}\{\frac{3*\x}{\pi}\}-\frac{\pi}{6})}});
But this returns a vast amount of errors I quite frankly doesnt understand.
It should look like something like this (curve to the right):
Best Answer
For starters you should think about the function, it can be reduced considerably. Specifically, cos(pi/6) = 1; also in the denominator you have pi/3 * (3*x/pi), that term simplifies to x.
Additionally, since you are not trying to typeset the equation, but rather evaluate the equation you can do away with the
\frac
and\cos
macros.I've used a
\foreach
loop to draw the curve as many times as you want. I've also automated drawing the axis ticks on the x axis. Note that by including an 'r' within thecos
I've told the function to see the units as radians.Running the above gives the following output: