📚 The CoCalc Library - books, templates and other resources
License: OTHER
\documentclass[varwidth=true, border=2pt]{standalone}12\usepackage{pgfplots}3\usepackage{tikz}45\begin{document}6\begin{tikzpicture}7\begin{axis}[8legend pos=south west,9axis x line=middle,10axis y line=middle,11grid = major,12%width=9cm,13%height=4.5cm,14grid style={dashed, gray!30},15xmin=-1, % start the diagram at this x-coordinate16xmax= 6, % end the diagram at this x-coordinate17ymin=-0.25, % start the diagram at this y-coordinate18ymax= 2.25, % end the diagram at this y-coordinate19axis background/.style={fill=white},20xlabel=$x$,21ylabel=$y$,22%xticklabels={-2,-1.6,...,7},23%yticklabels={-8,-7,...,8},24tick align=outside,25minor tick num=-3,26enlargelimits=true,27tension=0.08]28\addplot[domain=0:1, red, thick,samples=20] {0.5*x*x};29\addplot[domain=1:2, green, thick,samples=20] {x-0.5};30\addplot[domain=2:3, blue, thick,samples=500] {-0.5*(x-2)*(x-2)+x-0.5};31\addplot[domain=3:5, purple, thick,samples=20] {5-x};32\addplot[domain=5:7, orange, thick,samples=3] {0};33\addplot[domain=-3:0, orange, thick,samples=3] {0};34%\addlegendentry{$f_1(x)=\frac{1}{2}x^2$}35%\addlegendentry{$f_2(x)=x-\frac{1}{2}$}36%\addlegendentry{$f_2(x)=-\frac{1}{2} (x-2)^2+x-\frac{1}{2}$}37\end{axis}38\end{tikzpicture}39\end{document}404142