Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
BTBsung
#R version 3.3.2 #Bai 0.1.1 tinhKyVong <- function(ds, n){ i <- 0 s <- 0 for(i in 1:n){ s <- s + ds[i] } s / n } tinhPhuongSai <- function(ds, n){ i = 0 s = 0 tb = tinhKyVong(ds, n) for(i in 1:n){ s = s + (ds[i] - tb)^2 } s / (n - 1) } ds <- sample(1:10, size = 40, replace = TRUE) tinhKyVong(ds, 40) tinhPhuongSai(ds, 40) #Bai 0.1.2 #a) sixes <- function(n){ for(i in 1:n){ kq = sample(1:6,1) if(kq==6) return(TRUE) } return(FALSE) } sixes(20) #b) play <- function(n,N){ count <- 0 for(i in 1:N){ if(sixes(n) == TRUE) count = count + 1 } return(count/N) } play(5,20) #Bai 0.1.5 X <- c(1.3975068, 1.1253621, 0.7472591, 0.8144085,1.8202663, 0.8671346, 1.4210106, 1.678400513697046, 0.6182268, 1.9064036, 0.9360782, 1.1175578, 1.2527916, 1.9584229, 1.3689436, 1.5685716, 1.0691046, 1.6625395, 1.7949509) as.double(X) u <- sum(X)/20 o2 <- sum((X-u)^2)/(20-1) u o2 #Bai 0.1.6 #a) tungDongXuCanDoi <- function(n){ gieo <- c("sap", "ngua") for(i in 1:n){ kq <- sample(gieo) if(kq=="sap") print(1) if(kq=="ngua") print(0) } } tungDongXuCanDoi(10) #b) raSap <- function(){ xs <- sample(1:100,1) if(xs >= 1 && xs <= 35) return(TRUE) return(FALSE) } nhanTien <- function(n){ tien <- 0 for(i in 1:n){ if(raSap()==TRUE) tien = tien + 10 if(raSap()==FALSE) tien = tien - 10 } return(tien) } nhanTien(10) #Bai 0.2.1 x <- sample(1:100, size = 80, replace = TRUE) x timMucPhanVi <- function(x, p){ if(p<0 || p>100) return(FALSE) sort(x, decreasing = FALSE) i <- (p/100)*length(x) if(is.integer(i)== FALSE){ round(i) return(x[i]) } else{ return(x[i]+(p/100)*(x[i+1]-x[i])) } } timMucPhanVi(x,25) #Bai 0.2.2 #a) height <- seq(130,190,1) plot(height, dnorm(height, 156, 4.6), type= "l", ylab= "f(height)", xlab= "Height", main= "Ham mat do cua phu nu Viet Nam") #b) dnorm(160,156,4.6) #c) plot(height, pnorm(height, 156, 4.6), type= "l", ylab= "f(height)", xlab= "Height", main= "Ham phan phoi tich luy cua phu nu Viet Nam") #d) pnorm(150,156,4.6) #0.2.3 lam tuong tu 0.2.2 #0.2.4 #a) P <- function(k, lamda){#Ham tinh xac suat P(X<=k) s <- 0 for(i in 0:k){ s <- s + (lamda^i) * exp(-lamda) / factorial(i) } return (s) } P(2,4) #b) people <- seq(1,20,1) plot(people,dpois(people,4), type= "l", ylab= "f(people)", xlab= "People", main= "Ham phan phoi tich luy cua khach hang doi giao dich ATM") #c) #Do P(20,4)=1 X<-0:20 timMucPhanVi(X,75) #0.2.5 #a) tinhMatDoXacSuat <- function(x){ a <- 2 b <- 5 f <- (b^a)/(P(a,4))*(x^(-a-1))*exp(-b/x) return (f) } tinhMatDoXacSuat(4)#x=4, anpha =2, beta = 5 x <- seq(1,10,0.5) #b) plot(x, tinhMatDoXacSuat(x), type= "l", ylab= "f(x)", xlab= "x", main= "Ham mat do xac suat cua X") f = function(x, a = 2, b = 5){(b^a)/(P(a,4))*(x^(-a-1))*exp(-b/x)} #c) integrate(function(x = 2.75) f(x,2,5) , lower = 0, upper = Inf) #0.2.6 #a) hamMatDo <- function(x){ return( 2 * exp(-2*x) ) } x <- seq(1,20,1) plot(x,hamMatDo(x), type = "l", xlab= "x", ylab= "f(x)", main= "Ham mat do cua A") hamPhanPhoiTichLuy <- function(n){#P(X<=x) f<- function(x) 2 * exp(-2*x) s <- integrate(f,lower = 0, upper = n) return(s) } #c) hamPhanPhoiTichLuy(5)
run
|
edit
|
history
|
help
0
26-08-2020Teste
Hello, world!
ExDecaiEulerMin28-01-21
5 # SUMMARY PART B
Fibanocii sequence in r
R1
SEIR-Modell
AjusteNaoLinear
Gab1Bdicussão
16-09-2020ExPedro