I'm plotting a graph with the following code: (also, I don't think centering is working either)
Before I made a modification to the give code:
The code:
\centering
\begin{tikzpicture}[
declare function={
func(\x) = (\x < 0) * (2*\x) +
and (\x >= 0) * (2*\x+1)
;}
\begin{axis}[
axis x line=middle, axis y line=middle,
ymin=-5, ymax=5, ytick={-5,...,5}, ylabel=$y$,
xmin=-5, xmax=5, xtick={-5,...,5}, xlabel=$x$,
domain=-5:5,samples=101, % added
]
\addplot [blue,thick] {func(x)};
\end{axis}
\end{tikzpicture}
The error:
/Users/rafaelvergnaud/Desktop/hw10.tex:103: Package PGF Math Error: Sorry, an internal routine of the floating point unit got an ill-formatted floating point number `Y'. The unreadable part was near 'Y'. (in '(2Y5.0e0]<0)*(2(2Y5.0e0]))+and(2Y5.0e0]>=0)*(2(2Y5.0e0])+1)+'). [\addplot [blue,thick] {func(x)};]
/Users/rafaelvergnaud/Desktop/hw10.tex:103: Package PGF Math Error: Sorry, an internal routine of the floating point unit got an ill-formatted floating point number `0'. The unreadable part was near '0'. (in '(2Y5.0e0]<0)*(2(2Y5.0e0]))+and(2Y5.0e0]>=0)*(2(2Y5.0e0])+1)+'). [\addplot [blue,thick] {func(x)};]
/Users/rafaelvergnaud/Desktop/hw10.tex:103: Missing number, treated as zero. [\addplot [blue,thick] {func(x)};]
/Users/rafaelvergnaud/Desktop/hw10.tex:103: Illegal unit of measure (pt inserted). [\addplot [blue,thick] {func(x)};]
/Users/rafaelvergnaud/Desktop/hw10.tex:103: Missing = inserted for \ifdim. [\addplot [blue,thick] {func(x)};]
/Users/rafaelvergnaud/Desktop/hw10.tex:103: Missing number, treated as zero. [\addplot [blue,thick] {func(x)};]
/Users/rafaelvergnaud/Desktop/hw10.tex:103: Illegal unit of measure (pt inserted). [\addplot [blue,thick] {func(x)};]

