Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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.

Thanks!!

share|improve this question
add comment

1 Answer

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));
    else
        return 1;
}

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

share|improve this answer
add comment

Your Answer

 
discard

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.