# Tikz / pgfplot: plot Alternating Sequence

Is there any possibility to plot an alternating sequence?

Picture: Alternating sequence:

I don't need exacly the same output as above.

I tried the following:

\begin{tikzpicture}
\begin{axis}[
ymin = -1,
ymax = 1,
xmin = 0,
xmax = 4,
axis x line=center,
axis y line=left]
\end{axis}
\end{tikzpicture}


What I got is:

Any idea?

-
What is the value of (-1)^{1.5} ? –  Paul Gaborit Jun 24 '12 at 16:15

You need to make sure that you're evaluating your function at the right points. If you've set the domain to domain=1:5, you should set the number of samples to samples=5, then you'll get points for x=1,2,...,5.

Alternatively, you can explicitly provide a list of sampling points using samples at={1,...,5}.

\documentclass{article}
\usepackage{pgfplots}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
ymin = -1,
ymax = 1,
xmin = 0,
xmax = 5,
axis x line=center,
axis y line=left]