Question

Hi I need the R codes of the below Exercise 2.18 from Introducing Monte Carlo Methods...

Hi

I need the R codes of the below Exercise
2.18 from Introducing Monte Carlo Methods with R

0 0
Add a comment Improve this question Transcribed image text
Answer #1

уж uwnormalized

R code:

F1=function(x){
exp(-(x^2)/2) * ((sin(6*x))^2 + 3*(cos(x))^2*(sin(4*x))^2 + 1)
}
curve(F1)

F1(x) 0 1.0 1.5 2.0 2.5 3.0 3.5 4.0 2

approximate value of M: code: integrate(F1, lowerInf, upper Inf) It gives: 5.89434 with absolute error less than 0.00047 Therefore, the normalizing constant is 1/5.89434 = 0.1696543

(b) f M 903) 皿- sin i n -the CO

R code:

accept_reject_alg <- function(m)
{
D <- function(x) ((sin(6*x))^2 + 3*(cos(x))^2*(sin(4*x))^2 + 1)/5
random_sample = c()
iter_num = 0
while(length(random_sample) < m){
iter_num = iter_num+1
y = rnorm(n=1,mean=0,sd=1)
u=runif(n=1,min=0,max=1)
if(u < D(y))
random_sample = c(random_sample, y)
}
RETURN = list(random_sample, iter_num)
names(RETURN) = c("sample","no_of_iterations")
return(RETURN)
}

RESULT = accept_reject_alg(2500)
RESULT$sample
RESULT$no_of_iterations

(c)

ko5V2π = M: and M is the average number of iterations required to get one sample. . M no. of iterations / sample size 5276/2500 2.1104 k0.1683856

code: hist(RESULT$sample)

Histogram of RESULT$sample 0 寸 12 12 髦3 4 RESULTSsample

Add a comment
Know the answer?
Add Answer to:
Hi I need the R codes of the below Exercise 2.18 from Introducing Monte Carlo Methods...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Hi I need the R code of the the below problem from Introducing Monte Carlo Methods...

    Hi I need the R code of the the below problem from Introducing Monte Carlo Methods with R: Exercise 2.2 Two distributions that have explicit forms of the cdf are the logis- tic and Cauchy distributions. Thus, they are well-suited to the inverse transform method. For each of the following, verify the form of the cdf and then generate 10,000 random variables using the inverse transform. Compare your program with the built-in R functions rlogis and rcauchy, respectively e-(x-μ) /...

  • MONTE CARLO SIMULATION: So I am trying to figure out a MATLAB code to generate a...

    MONTE CARLO SIMULATION: So I am trying to figure out a MATLAB code to generate a Monte Carlo simulation for my mean and standard deviation values. I have a material (fat) with mean and standard deviation values as well as mean and standard deviation values for its thickness. I need to figure out a code that will plot and generate a monte carlo simulation. Any help would be greatly appreciated. Thanks

  • Please read all three pictures to get full understanding, no need to complete Monte Carlo simulation....

    Please read all three pictures to get full understanding, no need to complete Monte Carlo simulation. Just numerically price expectation: Interview question (JP Morgan) You have 10 blue balls and 8 red balls, lined up in a queue. What is the expected number of balls that have a neighbor of a different color? Hint: for each slot in the queue, define an indicator random variable. Apply the rule of total conditional expectation to evaluate the expectation of each indicator. Note...

  • Exercise 2 (Monte Carlo integration). Let (Xk)kzl be i.i.d. Uniform([0, 1]) RVs and let f: [0,1]...

    Exercise 2 (Monte Carlo integration). Let (Xk)kzl be i.i.d. Uniform([0, 1]) RVs and let f: [0,1] -- R be a continuous function. For each n2 1, let (f(X)f(X2).+f(Xn)) (3) In = -- .. + Sof(x) dx in probability. (i) Suppose o f (x)| dx (ii) Further assume that f lf(x)2 dx <o0. Use Chebyshef's inequality to show that :< oo. Show that In P (IIn-I2 alVnVar(f(X1)) a2 f(x)2 dx (4)

  • Problem 9 (for all students) Monte Carlo simulation is often used to analyze probabilities of failure...

    Problem 9 (for all students) Monte Carlo simulation is often used to analyze probabilities of failure of geotechnical engineering structures. a) For a case, where the limit state function, G, can be described by three normally distributed random variables such that G-Xi-X2x X3, describe a step-by-step methodology (i.e. an algorithm; MatLab code is not needed) that calculates the probability of failure with Monte Carlo simulation. (3 p) I. Il Running the algorithm that you proposed in a), you can visualize...

  • MONTE CARLO HYPOTHESIS TEST HELP?! We are given the following averages in categories (How much ti...

    MONTE CARLO HYPOTHESIS TEST HELP?! We are given the following averages in categories (How much time you spend a week on HW, on FB, READING, and LISTENING TO MUSIC: These were the averages for each category: HW = 12.0276 /wk FB = 385.403 /wk BOOKS = 42.4919 /wk MUSIC = 18.8011 /wk -- (Basically my hypothesis are testing whether or not my class does more or less when compared to graduate students) I NEED TO USE MY AVERAGES IN A...

  • [20 points] Problem 2 - Monte Carlo Estimation of Definite Integrals One really cool application of...

    [20 points] Problem 2 - Monte Carlo Estimation of Definite Integrals One really cool application of random variables is using them to approximate integrals/area under a curve. This method of approximating integrals is used frequently in computational science to approximate really difficult integrals that we never want to do by hand. In this exercise you'll figure out how we can do this in practice and test your method on a relatively simple integral. Part A. Let X be a random...

  • Java GUI Help! Hi, I have a Java GUI exercise that I need to complete and...

    Java GUI Help! Hi, I have a Java GUI exercise that I need to complete and was wondering if I could have a little bit of help... you can see it below. Create a simple graphical application that will enable a user to perform push, pop and peek operations on a stack and display the resulting stack (using toString) in a text area. Any help would be much appreciated! Thank you.

  • Hi i need a research about any subject related to one of these subject: energy methods...

    Hi i need a research about any subject related to one of these subject: energy methods finite element the research contain  the following Abstract introduction: literatur review methodology result and discussion conclucions references

  • Hi I need some extra help with that exercise. Thank you very much. 14.- From the...

    Hi I need some extra help with that exercise. Thank you very much. 14.- From the next exercise obtained the solution From the next e A component is attached to a wall with four 0,375-in.- diameter bolts (each acting in single shear). A load P is applied to the component as shown. The ultimate shearing stress for each bolt is 40 ksi. If the factor of safety is 2, determine the largest load P that can be applied to the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT