\STATE [algorithmic package]

June 7, 2012
By

(This article was first published on Xi'an's Og » R, and kindly contributed to R-bloggers)

I fought with my LαTεX compiler this morning as it did not want to deal with my code:

 \begin{algorithmic}[1]
 \STATE N=1000
 \STATE $\hat\pi=0$
 \FOR {I=1,N}
 \STATE X=RDN(1), Y=RDN(1)
 \IF {$\text{X}^2+\text{Y}^2<1$}
 $\hat\pi$ = $\hat\pi +1$
 \ENDIF
 \ENDFOR
 \RETURN 4*$\hat\pi/$N
 \end{algorithmic}
 

looking on forums for incompatibilities between beamer and algorithmic, and adding all kinds of packages, to no avail. Until I realised one \STATE was missing:

 \begin{algorithmic}[1]
 \STATE N=1000
 \STATE $\hat\pi=0$
 \FOR {I=1,N}
 \STATE X=RDN(1), Y=RDN(1)
 \IF {$\text{X}^2+\text{Y}^2<1$}
 \STATE $\hat\pi$ = $\hat\pi +1$
 \ENDIF
 \ENDFOR
 \RETURN 4*$\hat\pi/$N
 \end{algorithmic}
 

(This is connected with my AMSI public lecture on simulation, obviously!)


Filed under: Books, Kids, pictures, R, Statistics, Travel, University life Tagged: algorithmic, AMSI, Australia, Beamer, high school mathematics, LaTeX, Monte Carlo Statistical Methods, pi, R, simulation

To leave a comment for the author, please follow the link and comment on his blog: Xi'an's Og » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Tags: , , , , , , , , , , , , , , ,

Comments are closed.