Created
May 5, 2015 18:56
-
-
Save AndrewLJackson/434f1d60c10030a41315 to your computer and use it in GitHub Desktop.
Useful functions between 0 and 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| rm(list=ls()) | |
| graphics.off() | |
| # -------------------------------------------------------------------- | |
| # The Exponential decay function | |
| # http://en.wikipedia.org/wiki/Exponential_function | |
| # a sequence of x-values from 0 to 1000 | |
| x <- seq(0, 100, length=100) | |
| y.1 <- exp(- 0.01 * x) | |
| y.2 <- exp(- 0.1 * x) | |
| y.3 <- exp(- 1 * x) | |
| y.4 <- exp(- 10 * x) | |
| par(mfrow = c(1,2)) | |
| matplot(x, cbind(y.1, y.2, y.3, y.4), type = "l", ylab = "exp(x)", | |
| bty = "L") | |
| legend("topright", y = NULL, legend = paste(c(0.01, 0.1, 1, 10)), | |
| lty = 1, lwd = 1, col = 1:4, bty = "n", title = "Decay Rate" ) | |
| matplot(x, 1 - cbind(y.1, y.2, y.3, y.4), type = "l", ylab = "1 - exp(x)", | |
| bty = "L") | |
| legend("bottomright", y = NULL, legend = paste(c(0.01, 0.1, 1, 10)), | |
| lty = 1, lwd = 1, col = 1:4, bty = "n", title = "Decay Rate" ) | |
| # -------------------------------------------------------------------- | |
| # The gaussian function | |
| # http://en.wikipedia.org/wiki/Gaussian_function | |
| # a sequence | |
| z <- seq(-3, 3, length = 500) | |
| a <- 1 | |
| b <- 0 | |
| c <- 0.25 # this makes the denominator = 1 | |
| w <- a * exp(-((z - b)^2 / c)) | |
| par(mfrow = c(1,2)) | |
| plot(z, w, type = "l", bty = "L", main = "Gaussian") | |
| plot(z, 1 - w, type = "l", bty = "L", main = "1 - Gaussian") | |
| # -------------------------------------------------------------------- | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment