Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm searching for a function which looks similar to the gamma distribution in the following image (the blue one). It doesn't have to be exactly a gamma function. enter image description here

I need this for a programming project as weighting function. I.e. I have two parameters, minVal and maxVal. Between these two values the weight should be 1 (or near one). If x is lower than 'minVal' the weight decrease should be steep, if bigger than maxVal the weight should also decrease, but not as steep as below min.

Here a few examples for different minVal and maxVal (minVal and maxVal may be of any value, i.e. very small/large). There is no restriction for the integral of the function. Function Graphs

The best thing would be to have something like:

float getWeight(float x, float min, float max) {
    return fancyFunction(x,min,max);

The fancyFunction can be anything which can be calculated by a Java programm.


share|cite|improve this question
up vote 1 down vote accepted

found a solution. It is a combination of exponential and gamma function:

private static double getWeight(double x, double minVal, double maxVal) {
    if (x == 0)
        return minVal > 0 ? 0 : 1;
    if (x < minVal)
        return (Math.exp(x * 8 / minVal) - 1) / Math.exp(8);
    else if (x > maxVal)
        return 1 / Gamma.gamma((1 / (maxVal - minVal)) * (x + maxVal - 2 * minVal));
        return 1;

Here are some plots: 0.05 to 0.15 1 to 3 100 to 500

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.