Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

Maths Lab Assignment 3

Shreyansh Tripathi
CSE-4
220503
Q1.

Ans:
a)
# Define the probabilities of each event
probs <- c(0.4, 0.3, 0.2, 0.1)
# Define the possible values of X
x <- 0:3
# Calculate the mean of X
mean <- sum(x * probs)
# Print the result
print(paste("The mean is", mean))

b)
# Calculate the variance of X
variance <- sum((x - mean)^2 * probs)
# Print the result
print(paste("The variance of X is", variance))
Q2.

density <- function(x) {


ifelse(x >= 7 & x <= 8, 1, 0)
}
(a)
# Calculate the expected value of X
expected_value <- integrate(function(x) {x * density(x)}, lower = 7, upper =
8)$value
# Print the result
print(paste("Expected value of X:", expected_value))

(b)
variance <- integrate(function(x) {(x - 7.5)^2 * density(x)}, lower = 7, upper =
8)$value
# Print the result
print(paste("Variance of X:", variance))

(c)
# Calculate E(2X + 3)
expected_value <- 2 * integrate(function(x) {x * density(x)}, lower = 7, upper =
8)$value + 3
# Print the result
print(paste("Expected value of 2X + 3:", expected_value))

(d)
# Calculate E(X^2)
expected_value <- integrate(function(x) {x^2 * density(x)}, lower = 7, upper =
8)$value
# Print the result
print(paste("Expected value of X^2:", expected_value))
Q3.

(a)
p_success <- 0.4 # probability of success for each well
p_fail <- 1 - p_success # probability of failure for each well
# Probability that all wells fail
p_all_fail <- p_fail^4
# Probability that one or more wells succeed
p_one_or_more_success <- 1 - p_all_fail
p_one_or_more_success

(b)
p_success <- 0.4 # probability of success for each well
n_wells <- 4 # number of wells
# Calculate the probability of each possible number of successes
probs <- dbinom(0:n_wells, n_wells, p_success)
# Calculate the expected number of successes
expected_successes <- sum(0:n_wells * probs)
expected_successes

(c)
p_success <- 0.4 # probability of success for each well
p_no_success <- (1 - p_success)^4 # probability of no success for all four wells
p_no_success
Q4.

(a)
lambda <- 2.00 # average number of collisions
k <- 1 # number of collisions we want to calculate the probability for
# Using the dpois() function to calculate the probability of k collisions
prob <- dpois(k, lambda)
prob

(b)
lambda <- 2.00 # average number of collisions
k <- 2 # maximum number of collisions we want to consider
# Using the ppois() function to calculate the probability of at most k collisions
prob <- ppois(k, lambda)
prob

(c)
lambda <- 4.00 # average number of collisions in two weeks
k <- 2 # number of collisions we want to calculate the probability for
# Using the dpois() function to calculate the probability of k collisions
prob <- dpois(k, lambda)
prob
Q5.

mean <- 24
sd <- 4
a)
P(X > 44)
p_a <- 1 - pnorm(44, mean, sd)
p_a
b)
Find k so that P(X < k) = 0.0228
k <- qnorm(0.0228, mean, sd)
k
c) P(X < 14)
p_c <- pnorm(14, mean, sd)
p_c
Q6.

(a)
mean <- 10
sd <- 0.03
x <- 10.075
1 - pnorm(x, mean, sd)

(b)
mean <- 10
sd <- 0.03
x1 <- 9.97
x2 <- 10.03
pnorm(x2, mean, sd) - pnorm(x1, mean, sd)

(c)
mean <- 10
sd <- 0.03
p <- 0.15
qnorm(p, mean, sd)

You might also like