6

Can somebody help? The fill area is not symmetric. The goal is to be symmetric.

\documentclass[10pt]{article}
\usepackage{pgf,tikz}
\usetikzlibrary{arrows}
\pagestyle{empty}
\begin{document}
\definecolor{zzttqq}{rgb}{0.6,0.2,0.0}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
\draw[->,color=black] (-4.0,0.0) -- (4.0,0.0);
\foreach \x in {-4.0,-3.0,-2.0,-1.0,1.0,2.0,3.0}
\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) node[below] {\footnotesize $\x$};
\draw[->,color=black] (0.0,-0.5) -- (0.0,5.5);
\foreach \y in {,1.0,2.0,3.0,4.0,5.0}
\draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt) node[left] {\footnotesize $\y$};
\draw[color=black] (0pt,-10pt) node[right] {\footnotesize $0$};
\clip(-4.0,-0.5) rectangle (4.0,5.5);
\draw[color=zzttqq,fill=zzttqq,fill opacity=0.1, smooth,samples=50,domain=-2.0:2.0] plot(\x,{(\x/2.0)^(4.0)-\x^(2.0)+5.0}) -- (2.0,0.0) -- (-2.0,0.0) -- cycle;
\draw[smooth,samples=100,domain=-4.0:4.0] plot(\x,{((\x)/2.0)^(4.0)-(\x)^(2.0)+5.0});
\begin{scriptsize}
\draw[color=black] (-4.140000000000001,6.140000000000001) node {$f$};
\end{scriptsize}
\end{tikzpicture}
\end{document}

enter image description here

10

Jake's comment should have solved your problem. This is to show you another method.

This can be done with pgfplots and it is very easy.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11,width=4in}
\definecolor{zzttqq}{rgb}{0.6,0.2,0.0}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
  axis lines = middle,
  xmin=-5,
  xmax=5,
  ymin=0,
  ymax=6,
  xlabel=$t$,
  ylabel=$v$,
  xtick={-4,...,4},
  ytick={1,...,5},
]
\addplot[draw=zzttqq,samples=100,domain=-2.0:2.0,fill=zzttqq,fill opacity=0.1] {{((\x)/2.0)^(4.0)-\x^(2.0)+5.0}}\closedcycle;
\addplot[blue,thick,samples=100,domain=-4.0:4.0] {{((\x)/2.0)^(4.0)-\x^(2.0)+5.0}};
\end{axis}
\end{tikzpicture}

\end{document}

enter image description here

This uses fillbetween library of pgfplots:

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11,width=4in}
\definecolor{zzttqq}{rgb}{0.6,0.2,0.0}
\usepgfplotslibrary{fillbetween}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
  axis lines = middle,
  xmin=-5,
  xmax=5,
  ymin=0,
  ymax=6,
  xlabel=$t$,
  ylabel=$v$,
  xtick={-4,...,4},
  ytick={1,...,5},
]
\addplot[draw=none,samples=100,domain=-4.0:4.0,name path =A] {0}\closedcycle;
\addplot[blue,thick,samples=100,domain=-4.0:4.0,name path=B]
                                              {{((\x)/2.0)^(4.0)-\x^(2.0)+5.0}};
\addplot[zzttqq,fill opacity=0.1] fill between[of=A and B,soft clip={domain=-2:2},];
\end{axis}
\end{tikzpicture}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.