Question

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

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

% Imagine that we have obtained two samples with a correlation of r = 0.4

% for a sample size of 10. We do not know the population or have any other

% information.

%

% But we can assume that the true populations generating the two variables

% were normally distributed. We can then simulate a process in which we

% draw samples of size 10 from two independent Gaussian distributions and

% compute the correlation value observed in each sample.

%

% Such (Monte Carlo) simulations reveal that it is actually quite likely to

% obtain a correlation of r = 0.4 for a sample size of 10, even when the

% underlying distributions are independent. Thus, we should not believe the

% claim.

% Empirical (measured) correlation.

r_empirical = .4;

% We simulate two independent and normally distributed variables.

N = 10000; % We set the number of montecarlo simulations

n = 10; % The sample size

s1_sim = randn(N,n); % siulated distribution of samples

s2_sim = randn(N,n); % simulated distribution of samples

% compute the correlation coefficient

for ii = 1:N

  % Note, here we are using matlab's corr.m to compute the pearon

  % correlation instead of computing it manually.

  r_dist(ii) = corr(s1_sim(ii,:)',s2_sim(ii,:)','type' , 'Pearson' );

end

% We plot the distribution of correlation coefficients obtained this way.

figure('name','Test Correlation (Monte Carlo Method)','color','w');

% Let's compute the histogram of the distribution and trasform the

% distribution into a probabilities.

%

% We choose the sampling spacing between the bins.

binWidth = .01;

% We make bins that cover the full range fo values in P and are sampled at

% the resolution we decided using binWidth.

bins = min(r_dist):binWidth:max(r_dist);

% We now make a histogram of the distribution of these differences.

% We scale the dstributions properly to transform into probabilites.

[nn, xx] = hist(r_dist,bins);

bar(xx,nn / (N * binWidth),'k');

title('Distribution of the Montecarlo-simulated correlation coefficients','FontSize',14)

ylabel('Probability of occurrence','FontSize',14)

xlabel('Corr(s1,s2)','FontSize',14)

hold on

set(gca,'tickdir','out', 'box','off','FontSize',14)

% Get the limits of the y axis from the plot. We will use these for the

% next plots.

y = get(gca,'yLim');

% We can now show the empirical difference we simulated (d_empirical). The

% height of the distribution at the value of d_empirical is the probability

% that that difference comes from samples drawn from the same distribution.

plot([r_empirical,r_empirical],y*.99,'r-','lineWidth',2)

% We can obtain the probability of H0 being false by counting the number of

% randomly obtained correlation coefficient values that are larger than the

% empirical value and divide this by the total number of simulations that

% were run. Because the value can be larger or smaller than the mean we

% coupute the absolute value of the ditribution and r values.

p = sum(abs(r_empirical) < abs(r_dist))/N;

text(-0.8,y(2)*.95,sprintf('H0 is false with %2.4f probability.',p),'FontSize',14)

Add a comment
Know the answer?
Add Answer to:
MONTE CARLO SIMULATION: So I am trying to figure out a MATLAB code to generate a...
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
  • The assignment is to perform a Monte Carlo simulation for the probability distribution of rolling two...

    The assignment is to perform a Monte Carlo simulation for the probability distribution of rolling two die and taking the sum of the two die. Therefore, your random variable will be x=2,3,4,5,6,7,8,9,10,11,12 and you will obtain the probabilities for each of those random variables by a Monte Carlo simulation. The requirements to get full credit are 1. R script must run 2. When I run your R script the script should clearly display the mean, the standard deviation and a...

  • In Matlab, I am trying to figure out how to find and use a acetylene.mat to...

    In Matlab, I am trying to figure out how to find and use a acetylene.mat to perform an analysis. In the analysis, I must define independent and dependent variables, create a plot with each dependent variable with each independent variable, given each independent variable and calculate the mean, standard deviation, median, and range of each dependent variable. Finally, I need to give each independent variable plot a boxplot of each dependent variable.

  • I want Matlab code related to 14.35. 14.35 A Monte Carlo analysis can be used for...

    I want Matlab code related to 14.35. 14.35 A Monte Carlo analysis can be used for optimization. For example, the trajectory of a ball can be computed with 2 |(P14.35) x+yo 2 cos20o y=(tan0o)x where y the height (m), Go = the initial angle (radians), the initial velocity (m/s), g 9.81 m/s, and yo vo = 25 m/s, and Oo = 50", determine the maximum height and the corresponding x distance (a) analytically with calcu- lus and (b) numerically with...

  • in Matlab, Use the Monte Carlo analysis to compute the area of a circle with radius 1. print out your code, at least one figure on which the circle and ‘dart hits’ are shown, and numerical results fo...

    in Matlab, Use the Monte Carlo analysis to compute the area of a circle with radius 1. print out your code, at least one figure on which the circle and ‘dart hits’ are shown, and numerical results for N=10, 100,1000. For each N, repeat the calculation at least 5times.

  • 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-μ) /...

  • Solve the following Monte-Carlo simulation problem both with Excel data tables and @Risk. Include all your...

    Solve the following Monte-Carlo simulation problem both with Excel data tables and @Risk. Include all your answers directly in your Excel file using text boxes or comment boxes. Please show formulas used within excel. NCAA Sweatshirt Problem An enterprising OU student is trying to decide how many sweatshirts to print for an upcoming NCAA Basketball Tournament game. The final four teams have emerged from the quarterfinal round, and there is a week left until the semi-finals, which are then followed...

  • Solve the following Monte-Carlo simulation problem both with Excel data tables and @Risk. Include all your...

    Solve the following Monte-Carlo simulation problem both with Excel data tables and @Risk. Include all your answers directly in your Excel file using text boxes or comment boxes. Please show formulas used within excel. NCAA Sweatshirt Problem An enterprising OU student is trying to decide how many sweatshirts to print for an upcoming NCAA Basketball Tournament game. The final four teams have emerged from the quarterfinal round, and there is a week left until the semi-finals, which are then followed...

  • Need help with matlab code. If writing code out please make it where i can understand...

    Need help with matlab code. If writing code out please make it where i can understand and read it. I would prefer to see it in matlab form. Thanks Consider the RC Circuit shown below. Assume the excitation is a 10 kHz sine wave with amplitude of 1 volt. Derive expressions for the voltages across the resistor and the capacitor as time functions. Plot the voltages across the resistor and the capacitor over two periods using MATLAB and a reasonable...

  • I would like to have a better understanding of how to do Fourier transformations on Matlab....

    I would like to have a better understanding of how to do Fourier transformations on Matlab. If this is possible. Please show me how to: 1. have Matlab FIND the Fourier transformation of the two functions above. They do not have to be in the same program or anything. I just want to understand the syntax and semantics better. 2. THEN plot the Fourier transform that you found VIA MATLAB. The main thing that I am trying to do is...

  • Hi, I am trying to figure out how write a code to read in a list...

    Hi, I am trying to figure out how write a code to read in a list of integers separated by commas into an array in c++, while ignoring the commas. example input 5, 2, 8, 6, 3, 6, 9, 7 example array: int arr[] = {5,2,8,6,3,6,9,7};

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