Question: please use R code: function (muC1,sigmaC1,muC2,sigmaC2,Msim=10000) { # a grand loop simulation program for the lifetime of # a simple system of components. This system

please use R

please use R code: function (muC1,sigmaC1,muC2,sigmaC2,Msim=10000) { # a grand loop simulation

code:

function (muC1,sigmaC1,muC2,sigmaC2,Msim=10000) {

# a grand loop simulation program for the lifetime of

# a simple system of components. This system has

# two branches. The first branch fails when C1 fails.

# The second branch fails as soon as either of C2 or C3 fails.

#

# get alpha's and lambda's for Gamma lifetime RVs from the

# mu's and sigma's.

# Note C2 has the same distribution as C3, i.e.

# alpha3=alpha2, lambda3=lambda2

lambda1 = muC1/sigmaC1^2

alpha1 = muC1*lambda1

lambda2 = muC2/sigmaC2^2

alpha2 = muC2*lambda2

#

# initialize simulation summary holders

count.C1fail = 0 # number of times C1 fails before branch2

system.lifetime = rep(NA,Msim)

#

# begin grand loop

for (i in 1:Msim) {

C1 = rgamma(1,alpha1,lambda1)

C2 = rgamma(1,alpha2,lambda2)

C3 = rgamma(1,alpha2,lambda2)

branch2 = min(C2,C3)

system.lifetime[i] = max(C1,branch2)

if (C1

} # end grand loop

#

# final summary calculations and wrapup

PC1fail = count.C1fail/Msim

hist(system.lifetime,main="Simulated System Lifetimes")

meanL = mean(system.lifetime)

stddevL = sd(system.lifetime)

MOEL95pct = 1.96*stddevL/sqrt(Msim)

out = list(muC1,sigmaC1,muC2,sigmaC2,Msim,PC1fail,meanL,MOEL95pct)

names(out) = c("muC1","sigmaC1","muC2","sigmaC2","Msim","PC1fail","meanL","MOEL95pct")

out

}

2. From the "Anatomy of a Monte Carlo simulation" handout, get the system simulation program from Example 2 into a function called mx.system. a. (5) Run the program with muC1 = 100, sigmaC1 = 20, muC2 = 80, sigmaC2 = 40 and 10,000 simulations. Give me your calling command and copy the resulting values of PC1fail, meante and MOEL95pct as they appear in the Routput window. b. (10) Re-write the function without any loops and re-do the simulation from part (a). Give the same output and also the created histogram, and the function code itself. Hints: create all of the Cls in one command; similarly C2s and C3s. Then use pmaxl) and or pmin(). 2. From the "Anatomy of a Monte Carlo simulation" handout, get the system simulation program from Example 2 into a function called mx.system. a. (5) Run the program with muC1 = 100, sigmaC1 = 20, muC2 = 80, sigmaC2 = 40 and 10,000 simulations. Give me your calling command and copy the resulting values of PC1fail, meante and MOEL95pct as they appear in the Routput window. b. (10) Re-write the function without any loops and re-do the simulation from part (a). Give the same output and also the created histogram, and the function code itself. Hints: create all of the Cls in one command; similarly C2s and C3s. Then use pmaxl) and or pmin()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!