# Map the complex plane on itself
# x11(width = 8, height = 8) # Screen device commented out
# due to CRAN test requirements.
# Use it when trying this example
phasePortrait("z", xlim = c(-2, 2), ylim = c(-2, 2),
xlab = "real", ylab = "imaginary",
verbose = FALSE, # Suppress progress messages
nCores = 2) # Max. two cores allowed on CRAN
# not a limit for your own use
# \dontshow{
# R CMD check: make sure any open connections are closed afterward
foreach::registerDoSEQ()
doParallel::stopImplicitCluster()
# }
# A rational function
# \donttest{
# x11(width = 10, height = 8) # Screen device commented out
# due to CRAN test requirements.
# Use it when trying this example
phasePortrait("(2-z)^2*(-1i+z)^3*(4-3i-z)/((2+2i+z)^4)",
xlim = c(-8, 8), ylim = c(-6.3, 4.3),
xlab = "real", ylab = "imaginary",
nCores = 2) # Max. two cores allowed on CRAN
# not a limit for your own use
# \dontshow{
# R CMD check: make sure any open connections are closed afterward
foreach::registerDoSEQ()
doParallel::stopImplicitCluster()
# }
# }
# Different pType options by example of the sine function.
# Note the different equivalent definitions of the sine
# function in the calls to phasePortrait
# \donttest{
# x11(width = 9, height = 9) # Screen device commented out
# due to CRAN test requirements.
# Use it when trying this example
op <- par(mfrow = c(2, 2), mar = c(2.1, 2.1, 2.1, 2.1))
phasePortrait("sin(z)", xlim = c(-pi, pi), ylim = c(-pi, pi),
pType = "p", main = "pType = 'p'", axes = FALSE,
nCores = 2) # Max. two cores on CRAN, not a limit for your use
# \dontshow{
# R CMD check: make sure any open connections are closed afterward
foreach::registerDoSEQ()
doParallel::stopImplicitCluster()
# }
phasePortrait("sin(z)", xlim = c(-pi, pi), ylim = c(-pi, pi),
pType = "pm", main = "pType = 'pm'", axes = FALSE,
nCores = 2)
# \dontshow{
# R CMD check: make sure any open connections are closed afterward
foreach::registerDoSEQ()
doParallel::stopImplicitCluster()
# }
phasePortrait("sin", xlim = c(-pi, pi), ylim = c(-pi, pi),
pType = "pa", main = "pType = 'pa'", axes = FALSE,
nCores = 2)
# \dontshow{
# R CMD check: make sure any open connections are closed afterward
foreach::registerDoSEQ()
doParallel::stopImplicitCluster()
# }
phasePortrait(sin, xlim = c(-pi, pi), ylim = c(-pi, pi),
pType = "pma", main = "pType = 'pma'", axes = FALSE,
nCores = 2)
# \dontshow{
# R CMD check: make sure any open connections are closed afterward
foreach::registerDoSEQ()
doParallel::stopImplicitCluster()
# }
par(op)# }
# I called this one 'nuclear fusion'
# x11(width = 16/9*8, height = 8) # Screen device commented out
# due to CRAN test requirements.
# Use it when trying this example
# \donttest{
op <- par(mar = c(0, 0, 0, 0), omi = c(0.2, 0.2, 0.2, 0.2), bg = "black")
phasePortrait("cos((z + 1/z)/(1i/2 * (z-1)^10))",
xlim = 16/9*c(-2, 2), ylim = c(-2, 2),
axes = FALSE, xaxs = "i", yaxs = "i",
nCores = 2) # Max. two cores allowed on CRAN
# not a limit for your own use
# \dontshow{
# R CMD check: make sure any open connections are closed afterward
foreach::registerDoSEQ()
doParallel::stopImplicitCluster()
# }
par(op)# }
# Passing function objects to phasePortrait:
# Two mathematical celebrities - Riemann's zeta function
# and the gamma function, both from the package pracma.
# R's built-in gamma is not useful, as it does not work
# with complex input values.
# \donttest{
if(requireNamespace("pracma", quietly = TRUE)) {
# x11(width = 16, height = 8) # Screen device commented out
# due to CRAN test requirements.
# Use it when trying this example
op <- par(mfrow = c(1, 2))
phasePortrait(pracma::zeta, xlim = c(-35, 15), ylim = c(-25, 25),
xlab = "real", ylab = "imaginary",
main = expression(zeta(z)), cex.main = 2,
nCores = 2) # Max. two cores on CRAN, not a limit for your use
# \dontshow{
# R CMD check: make sure any open connections are closed afterward
foreach::registerDoSEQ()
doParallel::stopImplicitCluster()
# }
phasePortrait(pracma::gammaz, xlim = c(-10, 10), ylim = c(-10, 10),
xlab = "real", ylab = "imaginary",
main = expression(Gamma(z)), cex.main = 2,
nCores = 2) # Max. two cores allowed on CRAN
# not a limit for your own use
# \dontshow{
# R CMD check: make sure any open connections are closed afterward
foreach::registerDoSEQ()
doParallel::stopImplicitCluster()
# }
}
# }
# Using vapply for defining a whole function as a string.
# This is a Blaschke product with a sequence a of twenty numbers.
# See the documentation of the function vector2String for a more
# convenient space-saving definition of a.
# But note that a C++ version of the Blaschke product is available
# in this package (function blaschkeProd()).
# \donttest{
# x11(width = 10, height = 8) # Screen device commented out
# due to CRAN test requirements.
# Use it when trying this example
phasePortrait("vapply(z, function(z, a) {
fct <- ifelse(abs(a) != 0,
abs(a)/a * (a-z)/(1-Conj(a)*z), z)
return(prod(fct))
},
a = c(0.12152611+0.06171533i, 0.53730315+0.32797530i,
0.35269601-0.53259644i, -0.57862039+0.33328986i,
-0.94623221+0.06869166i, -0.02392968-0.21993132i,
0.04060671+0.05644165i, 0.15534449-0.14559097i,
0.32884452-0.19524764i, 0.58631745+0.05218419i,
0.02562213+0.36822933i, -0.80418478+0.58621875i,
-0.15296208-0.94175193i, -0.02942663+0.38039250i,
-0.35184130-0.24438324i, -0.09048155+0.18131963i,
0.63791697+0.47284679i, 0.25651928-0.46341192i,
0.04353117-0.73472528i, -0.04606189+0.76068461i),
FUN.VALUE = complex(1))",
pType = "p",
xlim = c(-4, 2), ylim = c(-2, 2),
xlab = "real", ylab = "imaginary",
nCores = 2) # Max. two cores allowed on CRAN
# not a limit for your own use
# \dontshow{
# R CMD check: make sure any open connections are closed afterward
foreach::registerDoSEQ()
doParallel::stopImplicitCluster()
# }
# }
# Much more elegant: Define the function outside.
# Here comes a Blaschke product with 200 random points.
# \donttest{
# define function for calculating blaschke products, even
# possible as a one-liner
blaschke <- function(z, a) {
return(prod(ifelse(abs(a) != 0, abs(a)/a * (a-z)/(1-Conj(a)*z), z)))
}
# define 200 random numbers inside the unit circle
n <- 200
a <- complex(modulus = runif(n), argument = runif(n)*2*pi)
# Plot it
# x11(width = 10, height = 8) # Screen device commented out
# due to CRAN test requirements.
# Use it when trying this example
phasePortrait(blaschke,
moreArgs = list(a = a),
pType = "p",
xlim = c(-2.5, 2.5), ylim = c(-1.7, 1.7),
xlab = "real", ylab = "imaginary",
nCores = 2) # Max. two cores allowed on CRAN
# not a limit for your own use
# \dontshow{
# R CMD check: make sure any open connections are closed afterward
foreach::registerDoSEQ()
doParallel::stopImplicitCluster()
# }
# }
# A hybrid solution: A one-liner expression given as a character string
# can be provided additional arguments with moreArgs
# \donttest{
n <- 73
a <- complex(modulus = runif(n), argument = runif(n)*2*pi)
# x11(width = 10, height = 8) # Screen device commented out
# due to CRAN test requirements.
# Use it when trying this example
phasePortrait("prod(ifelse(abs(a) != 0,
abs(a)/a * (a-z)/(1-Conj(a)*z), z))",
moreArgs = list(a = a),
pType = "p",
xlim = c(-2.5, 2.5), ylim = c(-1.7, 1.7),
xlab = "real", ylab = "imaginary",
nCores = 1) # Max. two cores allowed on CRAN
# not a limit for your own use
# \dontshow{
# R CMD check: make sure any open connections are closed afterward
foreach::registerDoSEQ()
doParallel::stopImplicitCluster()
# }
# }
# Note the difference in performance when using the C++ defined
# function blaschkeProd() provided in this package
# \donttest{
n <- 73
a <- complex(modulus = runif(n), argument = runif(n)*2*pi)
# Plot it
# x11(width = 10, height = 8) # Screen device commented out
# due to CRAN test requirements.
# Use it when trying this example
phasePortrait(blaschkeProd,
moreArgs = list(a = a),
pType = "p",
xlim = c(-2.5, 2.5), ylim = c(-1.7, 1.7),
xlab = "real", ylab = "imaginary",
nCores = 1) # Max. two cores allowed on CRAN
# not a limit for your own use
# \dontshow{
# R CMD check: make sure any open connections are closed afterward
foreach::registerDoSEQ()
doParallel::stopImplicitCluster()
# }
# }
# Interesting reunion with Benoit Mandelbrot.
# The function mandelbrot() is part of this package (defined
# in C++ for performance)
# \donttest{
# x11(width = 11.7, height = 9/16*11.7) # Screen device commented out
# due to CRAN test requirements.
# Use it when trying this example
op <- par(mar = c(0, 0, 0, 0), bg = "black")
phasePortrait(mandelbrot,
moreArgs = list(itDepth = 100),
xlim = c(-0.847, -0.403), ylim = c(0.25, 0.50),
axes = TRUE, pType = "pma",
hsvNaN = c(0, 0, 0), xaxs = "i", yaxs = "i",
nCores = 1) # Max. two cores allowed on CRAN
# not a limit for your own use
par(op)
# \dontshow{
# R CMD check: make sure any open connections are closed afterward
foreach::registerDoSEQ()
doParallel::stopImplicitCluster()
# }
# }
# Here comes a Julia set.
# The function juliaNormal() is part of this package (defined
# in C++ for performance)
# \donttest{
# x11(width = 11.7, height = 9/16*11.7) # Screen device commented out
# due to CRAN test requirements.
# Use it when trying this example
op <- par(mar = c(0, 0, 0, 0), bg = "black")
phasePortrait(juliaNormal,
moreArgs = list(c = -0.09 - 0.649i, R_esc = 2),
xlim = c(-2, 2),
ylim = c(-1.3, 1.3),
hsvNaN = c(0, 0, 0),
nCores = 1) # Max. two cores allowed on CRAN
# not a limit for your own use
par(op)
# \dontshow{
# R CMD check: make sure any open connections are closed afterward
foreach::registerDoSEQ()
doParallel::stopImplicitCluster()
# }
# }
Run the code above in your browser using DataLab