Search code examples
matlabstatisticsmontecarlo

How to use MATLAB Code for Monte Carlo Simulation?


`n = 10000; 
Min= Minimum Value;
Max= Maximum Value;
Mode= Most Likely Value;
X = [Min=5,Mode=7,Max=10];
Y = [Min=3,Mode=5,Max= 10];
Z = [Min=5,Mode=7,Max=12];
P= X*Y*Z;`

I have three parameters such as, X =( Min=5,Mode=7,Max=10); Y=(Min=3,Mode=5,Max=10); Z=(Min=5,Mode=7,Max=12). and P = XYZ; Now how can I write a MATLAB Code for Monte Carlo simulation for 10000 iteration to get P values? and how to plot normal distribution and cumulative distribution of the out put P values?


Solution

  • First of all you should calculate mean and variance of each distribution, to model it with normal distribution, then:

    Xrand = (Xvariance*randn(1,n)) + Xmean*ones(1,n);
    Yrand = (Yvariance*randn(1,n)) + Ymean*ones(1,n);
    Zrand = (Zvariance*randn(1,n)) + Zmean*ones(1,n);
    
    P = Xrand.*Yrand.*Zrand;
    
    plot(P);
    

    If you don't want to model with normal distribution, then you'll need some toolbox or implement the distribution yourself.