Kris
Kris

Reputation: 1556

How to generate a matrix of random numbers using the normal distribution in AMPL?

How can I generate a matrix of random numbers using the normal distribution in AMPL with mean and variance listed below?

param mean :=
1   45
2   35
3   40;

param variance :
    1       2       3 :=
1   1      -2      -1
2  -2      36      -8
3  -1      -8       9;

Upvotes: 1

Views: 1055

Answers (1)

Paul G.
Paul G.

Reputation: 632

AMPL supports some random number functions for your parameters. You can try something like this:

 param matrix {x in dimx, y in dimy} 
          = Normal(mean[x], variance[x, y]);

If you want to make sure to get only positive numbers, you should wrap the Normal function with the max function.

max(Normal(mean[x], variance[x, y]), 0);

Upvotes: 1

Related Questions