Computation Contest #4 Results and Solution

Words
204
Reading
1 min
Listen
Play
7y

Solution

The problem of this contest was to solve the exponential integral numerically:

I implemented an example solution in java which takes your a number x as input and integrates between 1/x and x by dividing it into 10⁹ sections:

public class abcd {
    public static double f(double x) { // Whatever function you want to integrate.
        return Math.exp(x)/x;
    }
    public static void main(String[] args) {
        double xMax = Double.parseDouble(args[0]);
        double xMin = 1/xMax;
        double Δx = (xMax-xMin)/1.0e9;
        double total = 0;
        for(double x = xMin; x < xMax; x += Δx) {
            total += f(x)*Δx;
        }
        System.out.println(total);
    }
}

This prints out when used for my own reputation(57):

1.0156434538674713E23

This is pretty close to the value supplied by wolframalpha(thanks to kaeserotor@kaeserotor for mentioning it.), but still only a small amount of digits.

In the next contest you will apply a slightly different method for integrating this same function. It will be a lot more accurate(f you plug in numbers of the right magnitude…).
So you might want to keep your code for comparison.

↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓

List of participants with their entries:

Name | Solution found | Comment

  • | -
    kaeserotor@kaeserotor | 1.0156373595307505e+23 for 57 | By the way you said you are unsure what your computer can handle. Most of the time if whatever operation you do inside the loop is not too long(a few lines) you can be pretty sure that on any modern computer(having a GHz processor) it should run within a minute.
    crokkon@crokkon | 9.178120876620503e+27 for 68.6 | correct.

↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓

Winners:

Congratulations kaeserotor@kaeserotor and crokkon@crokkon, you won 1 SBI each!

↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓

The next contest starts in 2 days. Don't miss it!