cubic-function.tex 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. \documentclass{article}
  2. \usepackage[pdftex,active,tightpage]{preview}
  3. \setlength\PreviewBorder{2mm}
  4. \usepackage{pgfplots}
  5. \usepackage{tikz}
  6. \usetikzlibrary{arrows, positioning, calc, intersections}
  7. \begin{document}
  8. % Define this as a command to ensure that it is same in both cases
  9. \newcommand*{\ShowIntersection}[2]{
  10. \fill
  11. [name intersections={of=#1 and #2, name=i, total=\t}]
  12. [red, opacity=1, every node/.style={above left, black, opacity=1}]
  13. \foreach \s in {1,...,\t}{(i-\s) circle (2pt)
  14. node [above left] {\s}};
  15. }
  16. \begin{preview}
  17. \begin{tikzpicture}
  18. \begin{axis}[
  19. axis x line=middle,
  20. axis y line=middle,
  21. width=15cm, height=15cm, % size of the image
  22. grid = major,
  23. grid style={dashed, gray!30},
  24. %xmode=log,log basis x=10,
  25. %ymode=log,log basis y=10,
  26. xmin=-2, % start the diagram at this x-coordinate
  27. xmax= 4, % end the diagram at this x-coordinate
  28. ymin=-7, % start the diagram at this y-coordinate
  29. ymax= 7, % end the diagram at this y-coordinate
  30. %/pgfplots/xtick={0,1,...,60}, % make steps of length 5
  31. %extra x ticks={23},
  32. %extra y ticks={0.507297},
  33. axis background/.style={fill=white},
  34. ylabel=y,
  35. xlabel=x,
  36. %xticklabels={,,},
  37. %yticklabels={,,},
  38. tick align=outside,
  39. tension=0.08]
  40. % plot the stirling-formulae
  41. \addplot[name path global=a, domain=-2:4, red, thick,samples=500]
  42. {-x*x*x + 4*x*x-x-4};
  43. \addplot[name path global=b, domain=0.25:4, blue, thick, dashed] {x-1.2};
  44. \addplot[name path global=c, domain=0.25:4, blue, thick, dashed] {x+0.42};
  45. \ShowIntersection{a}{b};
  46. \end{axis}
  47. \end{tikzpicture}
  48. \end{preview}
  49. \end{document}