MATLAB: How to generate a random vector with fixed sum and bounded elements

bounded random numberconstraintsfixed sumMATLABoptimizationrandom vector

I want to generate a random N element vector with a fixed sum: and each element is bounded as . is the fixed sum and specify upper bound on the element of the vector . I would appreciate any guidance.

Best Answer

Maybe I am not understanding something, but it seems like your problem is overconstrained.
You can easily make a length n vector whose elements are bounded by d, for example using a uniform distribution
x = rand(N,1).*d % where d is a vector of upper bounds for each element
you can also make a random vector with a specified sum using
x = rand(N,1);
xfixedSum = x/sum(x)*Etotal
But it seems that in general it is not possible to hold both constraints.