Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

📚 The CoCalc Library - books, templates and other resources

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