July 27th, 2007, 1:11 am
Sounds difficult to solve exactly in general, for instance, just finding a subset of the numbers that match a desired mean is NP-complete I believe. If I really had to solve it, I'd set it up as an integer program: For instance, let x_i be 0 or 1 depending on whether it's in the selection or not. Then if your numbers are K_i and you want to select N of them with a mean M and stdev S then you need: sum_i x_i K_i=MN and sum_i x_i (K_i-M)^2=(N-1)SD^2. You can rewrite this as: sum_i x_i a_i=1 and sum_i x_i b_i =1 for suitable a and b vectors. Still hard to solve even after you've fixed N. If you were willing to allow a tolerance in your mean and/or stdev you could make this into a quadratic program with integer variables and throw it into a optimization solver (see e.g., axioma, cplex, etc.).