Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
R (programming language)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Mandelbrot set === [[File:Mandelbrot Creation Animation.gif|thumb|200px|"Mandelbrot.gif" graphic created in R. (Note: Colors differ from actual output.)]] This [[Mandelbrot set]] example highlights the use of [[complex numbers]]. It models the first 20 [[iteration]]s of the [[equation]] <code>z = z<sup>2</sup> + c</code>, where <code>c</code> represents different [[Complex number|complex constants]]. Install the package that provides the <code>write.gif()</code> function beforehand: <syntaxhighlight lang="r"> install.packages("caTools") </syntaxhighlight> R Source code: <syntaxhighlight lang="r"> library(caTools) jet.colors <- colorRampPalette( c("green", "pink", "#007FFF", "cyan", "#7FFF7F", "white", "#FF7F00", "red", "#7F0000")) dx <- 1500 # define width dy <- 1400 # define height C <- complex( real = rep(seq(-2.2, 1.0, length.out = dx), each = dy), imag = rep(seq(-1.2, 1.2, length.out = dy), times = dx) ) # reshape as matrix of complex numbers C <- matrix(C, dy, dx) # initialize output 3D array X <- array(0, c(dy, dx, 20)) Z <- 0 # loop with 20 iterations for (k in 1:20) { # the central difference equation Z <- Z^2 + C # capture the results X[, , k] <- exp(-abs(Z)) } write.gif( X, "Mandelbrot.gif", col = jet.colors, delay = 100) </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)