You are on page 1of 2

URK20RA1020 EXPERIMENT 2

July 27, 2021

[2]: f<-function(x) 0.5*exp(-x)*x^2


g<-function(x) x*f(x)
h<-function(x) x^2*f(x)
EX1<-integrate(g,lower=0,upper=Inf)$value
print(paste('Mean',EX1))
EX2<-integrate(h,lower=0,upper=Inf)$value
Var<-(EX2-(EX1)^2)
print(paste('Variance',Var))
.
[1] "Mean 3.00000000261729"
[1] "Variance 2.9999999843056"

[3]: f<-function(x) (1/9)*x^2


g<-function(x) x*f(x)
h<-function(x) x^2*f(x)
EX1<-integrate(g,lower=0,upper=3)$value
print(paste('Mean',EX1))
EX2<-integrate(h,lower=0,upper=3)$value
Var<-(EX2-(EX1)^2)
print(paste('Variance',Var))
.
[1] "Mean 2.25"
[1] "Variance 0.337500000000002"

[4]: f<-function(x) (2/27)*(1+x)


g<-function(x) x*f(x)
h<-function(x) x^2*f(x)
EX1<-integrate(g,lower=2,upper=5)$value
print(paste('Mean',EX1))
EX2<-integrate(h,lower=2,upper=5)$value
Var<-(EX2-(EX1)^2)
print(paste('Variance',Var))
.
[1] "Mean 3.66666666666667"
[1] "Variance 0.722222222222225"

[6]: f<-function(x) (3/4)*(2*x-x^2)


g<-function(x) x*f(x)
.

1
h<-function(x) x^2*f(x)
EX1<-integrate(g,lower=0,upper=2)$value
print(paste('Mean',EX1))
EX2<-integrate(h,lower=0,upper=2)$value
Var<-(EX2-(EX1)^2)
print(paste('Variance',Var))
.
[1] "Mean 1"
[1] "Variance 0.2"

[ ]:
.

You might also like