Math Is Fun Forum

  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#1 Help Me ! » Integration: calculating the area under a parabolic graph » 2007-03-22 03:47:58

Milks
Replies: 1

ello

I originally posted this question on a programming forum, but haven't had a solution yet, so I'm throwing open to you math guys. Ignore the spod-talk bit, unless you're familiar with computer programming yourself it might not make much sense:

I'm trying to write a function that'll take a set of results, assign a probability to each result, and then pick one result at random, according to its probability.

Soooo... I thought I'd calculate the area under sections of a basic parabolic function (y = x²) to generate the skewed probabilities.

Because of the nature of this curve, the amount of skew is determined by the range of the parabola used, as x tends to zero, the gradient tends to zero, so using 0 - 0.001 would be only slightly skewed. As x tends to infinity, the gradient tends to infinity, so using values 0 - 100 the probabilities would be heavily skewed.

to recap then, my function would be passed a skew factor, essentially the upper limit of the parabolic graph to use. All I need do is divide the whole range into equal sections according to the number of values and determine the definite integral for each range of the parabola assigned to each of the possible values. Make sense? Good.

integrating y = x² gave me x³ / 3

from this I developed the following code:
vals = ["dog", "cat", "monkey", "horse", "marmotte", "hampster", "yetti", "ant", "mouse", "duck"];
skewfactor = 9;
trace(getProbabilities(vals, skewfactor));

function getProbabilities(vals: Array, skewfactor: Number): Array {
   
    var tot: Number = Math.pow(skewfactor, 3) / 3;
    var range: Number = skewfactor / vals.length;
   
    var probs: Array = new Array();
    var lastbound: Number = 0;
    var count: Number = 0;
    while(count < vals.length) {
        var ubound: Number = (count + 1) * range;
        probs[count] = ((Math.pow(ubound, 3) / 3) - (Math.pow(lastbound, 3) / 3)) / tot;
        lastbound = ubound;
        ++count;
    }
   
    return probs;
}


and it kinda worked. It produced a set of probabilities which looked like they fell in line with a simple parabola.

My problem is that no matter what skew value (i.e. max range) I pass in, it produces exactly the same results and I'm not sure if my maths is wrong, my theory on the nature of the curve is wrong or if my code is wrong.

Any thoughts, comments or pointers welcomed

so have I got the correct thinking with regards to the nature of a parabolic curve? have I integrated the equation correctly?

I'm getting pretty desperate now! tongue

Board footer

Powered by FluxBB