Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- documentclass[border=10]{standalone}
- usepackage{tikz}
- usepackage{pgfplots}
- pgfplotsset{compat=1.9}
- begin{document}
- % Explicit formula
- pgfmathdeclarefunction{explicit_sum}{1}{%
- pgfmathparse{(#1*(#1-1))/2}%
- }
- % The inner function
- pgfmathdeclarefunction{square}{1}{%
- pgfmathparse{#1*#1}%
- }
- % Compute the sum of another function
- % Does not work...
- pgfmathdeclarefunction{manual_sum}{1}{%
- %Parameter should be integral
- pgfmathtruncatemacrocnt{10*#1}
- pgfmathsetmacroret{0}
- foreach i in {1,...,cnt} {
- pgfmathsetmacroret{ret + sum(i)}
- }
- pgfmathparse{ret}
- }
- begin{tikzpicture}
- begin{axis}
- % Expected
- addplot[samples at={1,...,10}] {explicit_sum(x)};
- % Does not work
- addplot[samples at={1,...,10}] {manual_sum(x)};
- end{axis}
- end{tikzpicture}
- end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement