Search code examples
matlabmontecarlovariance

Monte Carlo in MATLAB


When I try to run this program:

n = 10000;

Constant = 5.0;
A = 10; 
B = 5;
C = 1.335;
Drand = (0.02*randn(1,n)) + 0.242*ones(1,n);
Erand = (0.005*randn(1,n)) + 0.536*ones(1,n); 
P = (Constant*A*B*(1.0/C))*(Drand.*(1.0-Erand.));
plot(P);

I get this error:

Error: "identifier" expected, ")" found.

where the variances are 0.02 and 0.005, and Mean are 0.242 and 0.536, respectively.


Solution

  • You have a . too much on the second last line. It should be:

     P = (Constant*A*B*(1.0/C))*(Drand.*(1.0-Erand));
    

    Also, your variances aren't actually 0.02 and 0.005. Think about it ;-)