ISADORE NABI & a.b.a.
CONJUNTO A UTILIZAR
CÓDIGO EN R
conjunto <- c(1:10) #Puede ser cualquier conjunto
I. PRODUCTO CARTESIANO
Ejemplo de producto cartesiano para el caso de dos conjuntos de tres elementos cada uno
CÓDIGO EN R
length(conjunto)*length(conjunto) prod_cart <- expand.grid(conjunto, conjunto)
ii. CONJUNTO POTENCIA (SIGMA ÁLGEBRA)
Ejemplo de conjunto potencia o sigma álgebra de un conjunto de tres elementos
CÓDIGO EN R
2^10 library(rje) c_potencia <- powerSet(conjunto)
iii. PERMUTACIONES SIN REPETICIÓN
Fórmula general para permutar un conjunto sin repetir elementos
Ejemplo de cómo permutar las letras de la palabra “APPLE” sin que se repitan letras
CÓDIGO EN R
perm_sin_rep = function(n, x) { factorial(n) / factorial(n-x) }
cantidad_perm_sin_rep <- 0 for(i in 1:10){ temp <- perm_sin_rep(10, i) cantidad_perm_sin_rep <- cantidad_perm_sin_rep + temp }
library(gtools) permutaciones_sinrep <- list(permutations(10, 1, conjunto), permutations(10, 2, conjunto), permutations(10, 3, conjunto), permutations(10, 4, conjunto), permutations(10, 5, conjunto), permutations(10, 6, conjunto), permutations(10, 7, conjunto), permutations(10, 8, conjunto), permutations(10, 9, conjunto), permutations(10, 10, conjunto))
III. permutaciones con repetición
Fórmula general para permutar un conjunto repitiendo sus elementos
Ejemplo de permutaciones con repetición para el caso de un conjunto de cuatro elementos
CÓDIGO EN R
library(gtools)
permutations(10, 10, conjunto, set = FALSE)
IV. COMBINACIONES SIN REPETICIÓN
Fórmula general para calcular combinaciones sin repetición
CÓDIGO EN R
comb_sin_rep = function(n, x) { factorial(n) / (factorial(x) * factorial(n – x)) # combinaciones sin repetición }
cantidad_comb_sin_rep <- 0 for(i in 1:10){ temp <- comb_sin_rep(10, i) cantidad_comb_sin_rep <- cantidad_comb_sin_rep + temp }
library(gtools) combinaciones_sinrep <- list(combinations(10, 1, conjunto), combinations(10, 2, conjunto), combinations(10, 3, conjunto), combinations(10, 4, conjunto), combinations(10, 5, conjunto), combinations(10, 6, conjunto), combinations(10, 7, conjunto), combinations(10, 8, conjunto), combinations(10, 9, conjunto), combinations(10, 10, conjunto))
V. COMBINACIONES CON REPETICIÓN
Fórmula general para calcular combinaciones con repetición
CÓDIGO EN R
comb_con_rep = function(n, x) { factorial(n + x – 1) / (factorial(x) * factorial(n – 1)) # combinaciones con repetición }
cantidad_comb_con_rep <- 0 for(i in 1:10){ temp <- comb_con_rep(10, i) cantidad_comb_con_rep <- cantidad_comb_con_rep + temp }
combinaciones_conrep <- list(combinations(10, 1, conjunto, repeats.allowed=TRUE), combinations(10, 2, conjunto, repeats.allowed=TRUE), combinations(10, 3, conjunto, repeats.allowed=TRUE), combinations(10, 4, conjunto, repeats.allowed=TRUE), combinations(10, 5, conjunto, repeats.allowed=TRUE), combinations(10, 6, conjunto, repeats.allowed=TRUE), combinations(10, 7, conjunto, repeats.allowed=TRUE), combinations(10, 8, conjunto, repeats.allowed=TRUE), combinations(10, 9, conjunto, repeats.allowed=TRUE), combinations(10, 10, conjunto, repeats.allowed=TRUE))
CUADRO RESUMEN
Like this: Like Loading...