As I said in your last question, use unit analysis to find your errors. It was good advice then and it is good advice now.
Let's examine your method:
public static int Normalize(
double n_bins,
double mu,
double sigma,
double gaussian)
It returns a bin index, so that should be an integer.
It takes a bin count; that should be an integer, not a double. It's not a physical quantity.
What is mu? It's a mean of the distribution. What is the distribution of? Speeds. So mu has units of meters per second.
What is sigma? It's the standard deviation of the distribution of speeds, so it also has units of meters per second.
What is gaussian? It is a sample from the distribution, so it also has units of meters per second.
But in your call:
Normalization.Normalize(binsCount, mass, T, gauss);
You've passed a bin count -- that's correct.
You've passed a mass -- we are expecting meters per second and you've passed kilograms, so that can't possibly be correct.
You've passed a temperature -- we are expecting meters per second and you've passed Kelvin, so that cannot possibly be correct.
And you've passed a sample, so that's correct.
What you should be passing is the mean speed, which you calculated in your last answer, and the standard deviation of speed, which you have an estimate of because you have a known standard deviation of one component of the velocity, and that's a good enough guess.
Again: unit analysis is a powerful tool to find mistakes. I wish C# made it easier to assign units to doubles; these sorts of problems would then be caught by the compiler. F# has this feature and it is quite nice.
UPDATE: It has come to my attention that the original poster does not understand what I mean by unit analysis.
Unit analysis is the technique of associating a "type" with every quantity in a physics problem, and then tracking that type through the problem. If at any point you discover that you have "mixed up" types, you know that there is a problem.
The basic rules of unit analysis are that units only sum with identical units, and units multiply and divide using the standard rules for multiplication and division.
For example, suppose we have some quantities: 10 kilograms, 5 meters, 2 seconds. Suppose we multiply kilograms by meters and divide by seconds; the momentum of an object that masses 10kg moving at 5 meters in 2 seconds is 25 kilogram meters per second.
If later on in our problem we have a quantity that is, say, energy, and we add the momentum to the energy by mistake, our unit analysis tells us that is wrong. 25 kg*m/s
cannot be added to anything that has units of energy because energy has units kg*m*m/(s*s)
, and so we know we've made a mistake somewhere.
Similarly, in the previous question I noted that we can use unit analysis to determine when we are doing a computation in grams, but we expect a value in kilograms. In that case at least we have two things that are both mass, but it is a serious error to use grams when kilograms are expected, and unit analysis can detect this problem.
This is particularly useful in programming because as we've just seen, it is very easy to make a mistake where you have a method that takes a speed and you pass it a temperature, which is meaningless. It was just sheer luck that 300K, the value you passed in for the speed, happened to be in the right ballpark, since 300m/s is also a reasonable speed for a nitrogen molecule. But that was luck. The correct thing to do is to figure out what the right speed to pass in is.