set.seed(5)
##### Simulate
##### "n" values from two normal distributions: "M" and "N"

n   <-  100000

M   <-  rnorm(n, mean = 230, sd = 1)
N   <-  rnorm(n, mean = 230, sd = 8)

##### Correlation and Covariance 

#   cor.test(M, N, method = "pearson")
#   cor.test(M, N, method = "kendall")
#   cor.test(M, N, method = "spearman")

#   cov(M, N)


#### Define the random variableS "M *(1 + N)" and "M + (M * N))"
################## Uncertainty 1 ##############################################

Original                <-  (M *(1 + N))
Mean_Original           <-  mean(Original)
StandardDeviation_Original  <-  sd(Original)

#################### Uncertainty of "(M *(1 + N))" using the Definition

U_Original_1        <-  ((1.96*StandardDeviation_Original/sqrt(n))
                                     /abs(Mean_Original))*100 

################## Uncertainty 2 ##############################################

Extended                <-  (M + (M * N))
Mean_Extended           <-  mean(Extended)
StandardDeviation_Extended  <-  sd(Extended)

#################### Uncertainty of "(M + (M * N))" using the Definition

U_Extended_2        <-  ((1.96*StandardDeviation_Extended/sqrt(n))
                                     /abs(Mean_Extended))*100 

################## Uncertainty 3 ##############################################

Reduced             <-  (M * N)
Mean_Reduced            <-  mean(Reduced)
StandardDeviation_Reduced   <-  sd(Reduced)

#################### Uncertainty of "(M * N)" using the Definition

U_Reduced_3     <-  ((1.96*StandardDeviation_Reduced/sqrt(n))
                                     /abs(Mean_Reduced))*100 

### Print the results ###

print(U_Original_1)
## [1] 0.02163037
print(U_Extended_2)
## [1] 0.02163037
print(U_Reduced_3)      
## [1] 0.02172291
############ Some graphs #######################################################
par(mfrow=c(3,2))
par(mar = c(2, 2,2,2)) # Set the margin on all sides to 2
hist(M, main = "Histogram of M", ylab = "Fréquence", col = "green")
hist(N, main = "Histogram of N", ylab = "Fréquence", col = "green")
hist(M * (1 + N), main = "Histogram of M * (1 + N)", ylab = "Fréquence", col = "blue")
hist(M + (M * N), main = "Histogram of M + (M * N)", ylab = "Fréquence", col = "blue")
hist(M * N, main = "Histogram of M * N", ylab = "Fréquence", col = "blue")

######## Fin ##################################################################