Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Inductive Databases And Constraint Based Data Mining

Authors: Saso Dzeroski ,Bart Goethals ,Pance Panov

2010th Edition

1489982175, 978-1489982179

More Books

Students also viewed these Databases questions

Question

=+Trainers from headquarters? Local trainers? Independent trainers?

Answered: 1 week ago