I am a physicist.
I have written a code on Monte Carlo simulation with condition loop.
I am getting some error in running this simulation code. I want to consider the positive value of the simulation result. When I run the code, I get an error.
I am running 10000 iterations and I have five parameters such as A,B,C,D and E. I am generating a random number for each parameter by using variance and mean of every parameter with the help of normal distribution.
The code is as follows:
n = 10000;
Constant = 5;
Arand = (3*10^(12)*randn(1,n)) + 7*10^(6)*ones(1,n);
Brand = (9*randn(1,n)) + 17*ones(1,n);
Crand = (2*10^(-4)*randn(1,n)) + 0.2*ones(1,n);
Drand = (0.0017*randn(1,n)) + 0.50*ones(1,n);
Erand = (0.00004*randn(1,n)) + 1.5*ones(1,n);
if P1 > 0
P1 = Constant*Arand.*Brand.*Crand.*Drand.*(1/Erand)
end
plot(P1);