Graphics, Figures & TablesPrinting series using tikz

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
koleygr
Posts: 21
Joined: Fri Jul 01, 2011 11:18 pm

Printing series using tikz

Post by koleygr »

I am trying to plot a math series such as:
$N_{t+1}=\frac{61}{60}N_t-5$ with $N_0=120$
and I want N_t>0
I suppose that I need a code like:

Code: Select all

 \begin{figure}[H]
 \centering
 \begin{tikzpicture}[scale=0.025]
  \draw[->] (0,0)--(320,0);
  \node at (330,-17) {$t$};
  \draw[->] (0,0)--(0,250);
  \node at (-17,200) {200};
  \node at (-17,250) {$N_t$};
  \node at (-17,20) {20};
  \node at (-17,120) {120};
  %\draw[scale=1.,domain=.1:4.2,smooth,variable=\x,blue] plot ({\x},{1+.1/\x});
  %\draw[-] (-0.04,1)--(0.04,1);
    \begin{scope}
    \newcommand*{\lasty}{120}
    \fill[blue] (0,6) circle (25pt);
    \foreach \x in {10,20,30,...,310} {%
      \fill[blue] (\x,61/60*\lasty-5) circle (25.pt);
      \xdef\lasty{61/60*\lasty-5}
    }
    \foreach \x in {50,100,150,...,300} {%
    \pgfmathsetmacro{\xpr}{int(\x/10)};
    \node at (\x,-10) {\xpr};
    }
  \end{scope}
\end{tikzpicture}
  \captionsetup{labelformat=empty}
  \caption{\textbf{Figure1:} The number should be less than zero after 31 years}
\end{figure}
My problem is that the calculations are not correct.
If you try these series in an excell file, you will find that in about 30 years (t->years) the series has to be zero and less than zero.

Could you please help me.

I also cant print the integer value on t axis
Using Kile 2.1.0 under Ubuntu software.
\XeLaTeX: XeTeX 3.1415926-2.2-0.9995.2 (TeX Live 2009/Debian)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
Stefan Kottwitz
Site Admin
Posts: 10323
Joined: Mon Mar 10, 2008 9:44 pm

Printing series using tikz

Post by Stefan Kottwitz »

I would use pgfplots for this.

A quick fix for the calculation would be:

\pgfmathparse{61/60*\lasty-5}\xdef\lasty{\pgfmathresult}

instead of \xdef\lasty{61/60*\lasty-5}.

Stefan
LaTeX.org admin
User avatar
Stefan Kottwitz
Site Admin
Posts: 10323
Joined: Mon Mar 10, 2008 9:44 pm

Printing series using tikz

Post by Stefan Kottwitz »

Here's a quick sample with pgfplots:

Code: Select all

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[
      axis y line = left,
      axis x line = bottom,
    ]
    \newcommand*{\lasty}{120}
    \foreach \x in {1,...,31} {
      \addplot[only marks] coordinates {(\x,\lasty)};
      \pgfmathparse{61/60*\lasty-5}
      \xdef\lasty{\pgfmathresult}
    }
  \end{axis}
\end{tikzpicture}
\end{document}
Stefan
LaTeX.org admin
koleygr
Posts: 21
Joined: Fri Jul 01, 2011 11:18 pm

Re: Printing series using tikz

Post by koleygr »

Thank you very much Stefan K.
It worked for both of my problems... for integers too
Using Kile 2.1.0 under Ubuntu software.
\XeLaTeX: XeTeX 3.1415926-2.2-0.9995.2 (TeX Live 2009/Debian)
Post Reply