Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Hey, I have a function which I would like to plot with latex/tikz. Since I'm just a beginner I really don't know how to do it. Don't get me wrong I don't have any problems with most functions but this one is a killer and the documentation is a little bit overwhelming.

jagged function

It would be great if someone could help me to plot this one.

share|improve this question
add comment

1 Answer 1

You can try the following.

part 1 : I think the difficult part is to get the fractional part of a number. The pgf/tikz function Mod does just that. Note that it is not the same as mod.

part 2 : one problem with the function f and tikz is the fact that tikz uses fixed point arithmetic and for this function you quickly exceed the limits. One way around this is to use the fpu library., but this is not what I will do. A pure tikz approach, noticing that u(100^n*x) is only there to get successive decimal digits of x, is shown below. Also, the sample rate of the plot changes the aspect of the plot dramatically.

\documentclass{minimal}

\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
[declare function={
    u(\x) = Mod(\x,1);
    j(\x) = 1- abs(u(\x)-0.5);
    f(\x) = j(100*\x)/10 + j(100*u(100*\x))/100 + j(100*u(100*u(100*\x)))/1000;}]

\draw[domain=-1:1,samples=50] plot (\x,{f(\x)});

\end{tikzpicture}
\end{document}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.