public static double[][] GetIsotopeDistribution(int n, double[] masses, double[] composition) { int len = masses.Length; int[][] partitions = NumUtil.GetPartitions(n, len); double[] ms = new double[partitions.Length]; double[] weights = new double[partitions.Length]; for (int i = 0; i < partitions.Length; i++) { weights[i] = 1; int[] partition = partitions[i]; for (int j = 0; j < len; j++) { ms[i] += partition[j] * masses[j]; for (int k = 0; k < partition[j]; k++) { weights[i] *= composition[j]; } } weights[i] *= NumUtil.Multinomial(n, partition); } int[] o = ArrayUtil.Order(ms); ms = ArrayUtil.SubArray(ms, o); weights = ArrayUtil.SubArray(weights, o); double[][] x = FilterWeights(ms, weights, null, 1e-6); ms = x[0]; weights = x[1]; x = FilterMasses(ms, weights, null, 0.2); ms = x[0]; weights = x[1]; return(new double[][] { ms, weights }); }