options(scipen=999)
options(digits=9)
cat("\014") # clear screen
rm(list=ls(all=TRUE))


ncr=function(n,r) (factorial(n)/(factorial(r)*factorial(n-r)))
x=c(0,1,2,3)
f=function(x) ncr(4,x)*ncr(3,3-x)/ncr(7,3)
fx=f(x)
xfx=x*f(x)
f(0)
f(1)
table=data.frame(x,fx,xfx)
table
Ex=sum(x*f(x))
Ex
Exx=sum(x*x*f(x))
Exx
variance=Exx-(Ex)^2
variance





new.function<-function() {s<-0
  for(i in 0:3) {
    s<-s+f(i)
    print(s)
  }
}
new.function






f=function(x) (1/18)*(3+2*x)
integrate(f,2,3)








ncr=function(n,r) (factorial(n)/(factorial(r)*factorial(n-r)))
x=c(0,1,2,3,4,5)
f=function(x) ncr(5,x)/32
fx=f(x)
table=data.frame(x,fx)
table


#g=function(x) 2*x
#integrate(integrate(g,0,y),0,1)



#integrate(f,0,1,abs.tol = 0.001,stop.on.error = TRUE)

#integrate(f,0,1,abs.tol = 0.000000000000000001)