Notes
Notes - notes.io |
k1b=table(k1)
k1b
b=barplot(k1b, col=2, las=1, ylim=c(0,30), main="wykres 1")
str(b)
text(b, k1b+5, labels = k1b)
##################################################################
k1b
k2b=table(k2)
k2b
M=rbind(k1b,k2b)
M
nazwy = c("a")
b=barplot(M,col=c(2,3),las=1,ylim=c(0,30), main="wykres 2", beside=T,space=c(0,2,1),names.arg = c(1:6))
str(b)
b
test(b, M+2, labels=M)
####################################################
choose(35, 5)
kupon = c(2, 5, 10, 15, 20)
lotto <- function(kupon, n)
{
wygr1=c(0,0,0,0,0,0) ## wygrane
for(i in c(1:n)) # (1,2,3,...,n)
{
los=sample(c(1:35),5,replace=F)
trafione = length(intersect(kupon,los))+1
switch(trafione,
{wygr1[1]=wygr1[1]+1},
{wygr1[2]=wygr1[2]+1},
{wygr1[3]=wygr1[3]+1},
{wygr1[4]=wygr1[4]+1},
{wygr1[5]=wygr1[5]+1},
{wygr1[6]=wygr1[6]+1})
}
wygr1b = wygr1/n # prawdopodobieństwo empiryczne
num1=round(100*wygr1b,1) # w procentach do 1 miejsce
results=rbind(num1)
colnames(results) = c(0:5)
rownames(results)=c("%")
tytul = paste("Liczba losowan = ",n)
b=barplot(wygr1b, col=2, las=1, ylim=c(0,1), names=c(0:5), main=tytul)
text(b, wygr1b+0.2, labels = num1, xpd=T)
return(results)
}
kupon=c(1,2,5,10,15)
lotto(kupon, 100)
##################################################### ZADANIE 1 LOTTO
choose(35, 5)
kupon = c(2, 5, 10, 15, 20)
lotto <- function(kupon, n)
{
wygr1=c(0,0,0,0,0,0) ## wygrane
wygr2=c(0,0,0,0,0,0)
for(i in c(1:n)) # (1,2,3,...,n)
{
los=sample(c(1:35),5,replace=F)
trafione = length(intersect(kupon,los))+1
kupon2=sample(c(1:35),5,replace=F)
trafione2 = length(intersect(kupon,los))+1
switch(trafione,
{wygr1[1]=wygr1[1]+1},
{wygr1[2]=wygr1[2]+1},
{wygr1[3]=wygr1[3]+1},
{wygr1[4]=wygr1[4]+1},
{wygr1[5]=wygr1[5]+1},
{wygr1[6]=wygr1[6]+1})
switch(trafione2,
{wygr2[1]=wygr2[1]+1},
{wygr2[2]=wygr2[2]+1},
{wygr2[3]=wygr2[3]+1},
{wygr2[4]=wygr2[4]+1},
{wygr2[5]=wygr2[5]+1},
{wygr2[6]=wygr2[6]+1})
}
wygr1b = wygr1/n # prawdopodobieństwo empiryczne
wygr2b = wygr2/n
num1=round(100*wygr1b,1) # w procentach do 1 miejsce
num2=round(100*wygr2b,1)
results=rbind(wygr1b,wygr2b) ### macierz wynikow
results2=rbind(num1,num2)
colnames(results) = c(0:5)
rownames(results)=c("prawd","prawd")
tytul = paste("Liczba losowan = ",n)
b=barplot(results, col=c(2,3), las=1, ylim=c(0,1),
names=c(0:5), main=tytul, beside=T, space=c(0.5,1))
text(b, results+0.2, labels = results2, xpd=T, cex =0.8)
return(results)
}
kupon=c(1,2,5,10,15)
lotto(kupon, 100)
### ZADANIE 2
# Prawo wielkich liczb
cummean <- function(v)
{
l = length(v)
u = cumsum(v)
for(i in c(1:l))
{
u[i]=u[i]/i
}
return(u)
}
v = c(1,1,1,1,0)
########(v)
######vec1=c(1,2,3,0,0,0)
cummean(vec1)
pwl<-function(n,m)
{
los=runif(m,0,1)
plot(c(1:m), cummean(los), type="l", ylim=c(0,1), las=1,cex.axis=0.75)
if(n>1)
{
los=runif(m,0,1)
lines(c(1:m), cummean(los),type="l")
}
}
pwl(1,100)
abline(h=0.5,col=2)
#####################################################################
cummean <- function(v)
{
l = length(v)
u = cumsum(v)
for(i in c(1:l))
{
u[i]=u[i]/i
}
return(u)
}
v = c(1,1,1,1,0)
########(v)
######vec1=c(1,2,3,0,0,0)
cummean(vec1)
pwl<-function(n,m)
{
los=rcauchy(m,0,1)
plot(c(1:m), cummean(los), type="l", ylim=c(-50,50), las=1,cex.axis=0.75)
if(n>1)
{
for(i in c(2:n))
{
los=rcauchy(m,0,1)
lines(c(1:m), cummean(los),type="l")
}
}
}
pwl(100,1000)
abline(h=0.5,col=2)
abline(h=1)
############################################ Zadanie 3 histogramy i centralne twierdzenie graniczne
x1 = rnorm(200,mean=100,sd=16)
h=hist(x1,breaks=20,las=1,xlim=c(0,200),freq=F,ylim=c(0,0.04))
str(h)
h$counts
arg=seq(40,160,0.1)
wart=dnorm(arg,100,16)
lines(arg,wart,col=2)
### CTG
ctg <- function(n,m)
{
sum = numeric()
los = runif(m, min=0, max=1)
sum[1]=sum(los)
plot(c(1:m), cumsum(los), type="l",
ylim=c(0, 100), las=1, cex.axis=0.75)
if(n>1){
for(i in c(2:n)){
los=runif(m,0,1)
sum[i]=sum(los)
lines(c(1:m), cumsum(los), type="l")
}
}
return(sum)
}
dane = ctg(300,100)
hist(dane, breaks =15, freq=F, las=1,ylim =c(0,0.2), xlim = c(30, 70))
arg=seq(30,70,0.1)
m=50
s=sqrt(100/12)
wart=dnorm(arg,m,s)
lines(arg,wart,col=2,lwd=2)
###### Fibonacci
fib = function(n)
{
u=numeric()
u[1]=1
u[2]=1
for(i in c(3:n))
{
u[i]=u[i-1]+u[i-2]
}
return(u)
}
fib(10)
v1
v2=digit(v1,1)
v2
cyfra <- function(x,n)
{
y=as.character(abs(x))
d=substr(y,n,n)
d2=as.numeric(d)
return(d2)
}
cyfra(345,2)
v1=fib(100)
v2=cyfra(v1,1)
v2
v3=table(v2)
v3
barplot(v3,las=1,col=2)
v4=cyfra(v1,2)
v4
v5=table(v4)
v5
barplot(v5,col=2,las=1)
################ modulo
modulo <- function(x,n)
{
u=numeric()
u[1]=x
for(i in c(2:n))
{
u[i]=(3*u[i-1])%%1
}
return(u)
}
v1=modulo(0.134,300)
v1
hist(v1,freq=F,ylim=c(0,1.5))
plot(c(1:300),v1,type="l")
########### test x2, rzut kostka 12 scienna
wyniki = c(4,6,9,5,11,4,3,4,6,7,9,6)
wyniki
names(wyniki)=c(1:12)
wyniki
barplot(wyniki,ylim=c(0,15),las=1,col=2)
abline(h=74/12,col=2)
chisq.test(wyniki)
|
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team