The plasma effect: correction

[This article was first published on Saturn Elephant, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

There’s a kind of error in the previous post. In this formula: \[ \exp\Bigl(-\frac{{(i/n-0.5)}^2 + {(j/n-0.5)}^2}{0.025^2} \Bigr), \] the indices \(i\) and \(j\) should range from \(0\) to \(n\), and \(n\) must be even in order to get something centered. See the corrected code for details:

fplasma4 <- function(n = 400L, gaussianMean = -50, gaussianSD = 5) {
  n <- n + 1L
  M <- matrix(
    rnorm(n*n, gaussianMean, gaussianSD), 
    nrow = n, ncol = n
  )
  FT <- dft(M)
  n <- n - 1L
  for(i in seq(n+1L)) {
    for(j in seq(n+1L)) {
      FT[i, j] <- FT[i, j] * 
        exp(-(((i-1L)/n - 0.5)^2 + ((j-1L)/n - 0.5)^2) / 0.025^2)
    }
  }
  IFT <- dft(FT, inverse = TRUE)
  colorMap1(IFT, reverse = c(FALSE, FALSE, TRUE))
}

The funny point is that the result is more interesting with the “error”. But it is not bad without it:

To leave a comment for the author, please follow the link and comment on their blog: Saturn Elephant.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)