Reputation: 1005
I would like to be able to generate these bellcurves from very little data:
I'm looking for a function in php that would give me the data generated by these bell curves. I don't know yet what I'm going to use to display them, but I need the data first.
I'm not very good at math, I've tried creating some normal distribution, but there isn't an easy way to say: "I want a thin bell curve" or "I want a large one".
Maybe using the arguments that are on top of the right side of the picture above might be cool.
Would someone know how I can reproduce the datapoints of these graphs in PHP ?
Thank you!
Upvotes: 2
Views: 3349
Reputation: 18446
Well, you could look up the formula of the normal distribution's probability density on Wikipedia.
A PHP implementation of this function would look like this:
function normal($x, $mu, $sigma) {
return exp(-0.5 * ($x - $mu) * ($x - $mu) / ($sigma*$sigma))
/ ($sigma * sqrt(2.0 * M_PI));
}
This function will give you the value of the bell curves you posted.
I really suggest you read the Wikipedia article on the function, but to put it simply, $mu
marks the position of the central peak of the bell curve and $sigma
determines its width (a larger value for $sigma
means a broader distribution).
Upvotes: 6