Advertisement
Guest User

Untitled

a guest
Feb 5th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. documentclass[border=10]{standalone}
  2.  
  3. usepackage{tikz}
  4. usepackage{pgfplots}
  5. pgfplotsset{compat=1.9}
  6.  
  7. begin{document}
  8. % Explicit formula
  9. pgfmathdeclarefunction{explicit_sum}{1}{%
  10. pgfmathparse{(#1*(#1-1))/2}%
  11. }
  12.  
  13. % The inner function
  14. pgfmathdeclarefunction{square}{1}{%
  15. pgfmathparse{#1*#1}%
  16. }
  17.  
  18. % Compute the sum of another function
  19. % Does not work...
  20. pgfmathdeclarefunction{manual_sum}{1}{%
  21. %Parameter should be integral
  22. pgfmathtruncatemacrocnt{10*#1}
  23. pgfmathsetmacroret{0}
  24. foreach i in {1,...,cnt} {
  25. pgfmathsetmacroret{ret + sum(i)}
  26. }
  27. pgfmathparse{ret}
  28. }
  29.  
  30. begin{tikzpicture}
  31. begin{axis}
  32. % Expected
  33. addplot[samples at={1,...,10}] {explicit_sum(x)};
  34.  
  35. % Does not work
  36. addplot[samples at={1,...,10}] {manual_sum(x)};
  37. end{axis}
  38. end{tikzpicture}
  39.  
  40. end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement