Generate matrix of random number with constraints

847 Views Asked by At

I want to generate a matrix of random numbers (normrnd with mean == 0) that satisfy the following constraints using MATLAB (or any other language)

  1. The sum of the absolute values in the matrix must equal X
  2. The largest abs(single number) must equal Y
  3. The difference between the number and its 8 neighbors (3 if in corner, 5 if on edge) must be less than Z

It would be relatively easy to satisfy one of the constraints, but I can't think of an algorithm that satisfies all of them...

Any ideas?

A very simply 3 x 3 where 5 is the max element value, 30 is the sum, and 2 is the difference
5 4 3
4 4 2
3 2 3

1

There are 1 best solutions below

1
On

It looks from your formulation that you want Gaussian (that is, normal) random variables that satisfy those three constraints.

That's impossible (as I already said).

Normal (or Gaussian) random variables are unbounded. If you impose a condition on the sum of absolute values, the random variables won't be normal anymore.

The same type of reasoning applies to the other two conditions. Any of those conditions inevitably spoils the Gaussian character of the random variables.