[Tex/LaTex] Graphing a simple exponential function

graphspgfplots

As I'm quite new to LaTeX. I wanted to graph the following function

F_{(x)} = \dfrac{9}{10}\cdot(-1)^x+1 

or basically:

Exponential Function

I tried

\usepackage{pgfplots}
\usepackage[margin=0.5in]{geometry}

\pgfplotsset{width=10cm,compat=1.9}
\usepgfplotslibrary{external}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    axis lines = left,
    xlabel = $x$,
    ylabel = {$f(x)$},
]
\addlegendentry{$x^2 - 2x - 1$}
%Here the blue parabola is defined
\addplot [
    domain=-10:10,
    codomain=0:1,
    samples=100,
    ]
    {9/10(-1^(-x)+1)};
\addlegendentry{$x^2 + 2x + 1$}

\end{axis}
\end{tikzpicture}
\end{document}

I got quite horrible results:
Result

What could I do to actually make it work?

Best Answer

enter image description here

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

\begin{align*}
  f(x) &= \frac{9}{10} (-1)^x + 1
\intertext{Apply the rules of powers.}
  &= \frac{9}{10} e^{x \ln(-1)} + 1
\intertext{Here $\ln(-1)$ is the complex logarithm}
  \ln(-1) &= \ln(e^{i\pi}) = i \pi
\intertext{One has}
  f(x) &= \frac{9}{10} e^{i \pi x} + 1
\intertext{Split into real and imaginary part:}
  \operatorname{Re}[f(x)] &= \frac{9}{10} \cos(\pi x) + 1 \\
  \operatorname{Im}[f(x)] &= \frac{9}{10} \sin(\pi x)
\end{align*}

\begin{tikzpicture}
  \begin{axis}[
    axis lines=left,
    xlabel=$x$,
    ylabel={$f(x)$},
    domain=-10:10,
    samples=200,
    no markers]
    \addplot { 9/10 * cos(deg(pi*x)) + 1 };
    \addplot { 9/10 * sin(deg(pi*x)) };
  \end{axis}
\end{tikzpicture}

\end{document}
Related Question