Can someone provide an explanation and a fix for the fact that my plot is not what is expected? The function is symmetric with respect to the y-axis. The plot correctly shows the function for positive values of x, but not so for negative values. Here is my code:
\documentclass[10pt]{article}
\usepackage{pgf,tikz}
\usetikzlibrary{arrows}
\usepackage{fouriernc}
\begin{document}
\begin{tikzpicture}[>=latex,x=1.3cm]
\fill[fill=lightgray] (0,0) -- plot[domain=0:1,samples=100] (\x,{sqrt(abs(\x))-\x^2});
\fill[fill=lightgray] plot[domain=1:2,samples=100] (\x,{sqrt(abs(\x))-\x^2}) -- (2,0);
\draw[thick,domain=-1:2.2,samples=100] plot (\x,{sqrt(abs(\x))-\x^2}) node[right] {\footnotesize $f(x)=\sqrt{|x|}-x^2$};
\foreach \x in {-1,1,2,3}
\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) node[below] {\footnotesize $\x$};
\foreach \y in {-3,-2,-1,1}
\draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt) node[left] {\footnotesize $\y$};
\draw[->,thick] (-2,0) -- (4,0) node[above left]{\footnotesize $x$};
\draw[->,thick] (0,-4) -- (0,2) node[below right]{\footnotesize $f(x)$};
\end{tikzpicture}
\end{document}
Here is what I get with this code:


plot (\x,{sqrt(abs(\x))-(\x)^2})(I added parentheses). – jub0bs Dec 08 '13 at 20:00pgfplots(less code, easier to understand and no(\x)). – remus Dec 09 '13 at 08:36