Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pdf("fig_06.pdf", width = 5, height = 5)
- par(bty = "n", las = 1, mar = c(4, 4, 1, 1) + 0.2)
- #---- Primero a lo bestia
- repetir <- 10000
- n <- 7
- trozos <- numeric(n)
- as <- matrix(NA, nrow = n, ncol = repetir) # para guardar las repeticiones
- for (i in 1:repetir) {
- trozos <- rexp(n, 0.1)
- trozos <- trozos/sum(trozos)
- trozos <- sort(trozos, decreasing = TRUE) # ordenarlos de mayor a menor
- as[, i] <- trozos
- }
- distribucion <- rowMeans(as) # longitudes medias
- # gráfico
- plot(1:n, distribucion, lwd = 2, bty = "n", xlab = "Rango", ylab = "Longitud", type = "h",
- ylim = c(0, 1.1 * max(distribucion)), col = "royalblue")
- text(1:n, distribucion, round(distribucion, 2), cex = 0.8, pos = 3)
- legend("topright", bty = "n", cex = 0.8, c("exponencial", "suma arm."), lty = c(1, 0), lwd = c(2, NA), pch = c(NA, 1), col = c("royalblue", "red"))
- #---- Ahora la bella para hacer la suma de armónicos
- sum_arm <- function(n) {
- a <- numeric(n)
- for (i in 1:n) {
- for (j in 1:i) {
- a[j] <- a[j] + 1/i
- }
- }
- a/n
- }
- points(sum_arm(n), col = "red")
- dev.off()
Advertisement
Add Comment
Please, Sign In to add comment