2d-parted-function.tex 1.0 KB

1234567891011121314151617181920212223242526
  1. \begin{tikzpicture}
  2. \begin{axis}[
  3. legend pos=south west,
  4. axis x line=middle,
  5. axis y line=middle,
  6. grid = major,
  7. grid style={dashed, gray!30},
  8. xmin=-1, % start the diagram at this x-coordinate
  9. xmax= 6, % end the diagram at this x-coordinate
  10. ymin=-0.25, % start the diagram at this y-coordinate
  11. ymax= 2.25, % end the diagram at this y-coordinate
  12. axis background/.style={fill=white},
  13. xlabel=$x$,
  14. ylabel=$y$,
  15. tick align=outside,
  16. minor tick num=-3,
  17. enlargelimits=true,
  18. tension=0.08]
  19. \addplot[domain=0:1, red, thick,samples=20] {0.5*x*x};
  20. \addplot[domain=1:2, green, thick,samples=20] {x-0.5};
  21. \addplot[domain=2:3, blue, thick,samples=500] {-0.5*(x-2)*(x-2)+x-0.5};
  22. \addplot[domain=3:5, purple, thick,samples=20] {5-x};
  23. \addplot[domain=5:7, orange, thick,samples=3] {0};
  24. \addplot[domain=-3:0, orange, thick,samples=3] {0};
  25. \end{axis}
  26. \end{tikzpicture}