Approximate ∫((e^x)/(x^x))dx You are to approximate the value of:



Where your input is I.

Rules


You may not use any built-in integral functions.
You may not use any built-in infinite summation functions.
Your code must execute in a reasonable amount of time ( &lt; 20 seconds on my machine)
You may assume that input is greater than 0 but less than your language's upper limit.
It may be any form of standard return/output.


You can verify your results at Wolfram | Alpha (you can verify by concatenating your intended input to the linked query).

Examples

(let's call the function f)

f(1) -> 2.18273
f(50) -> 6.39981
f(10000) -> 6.39981
f(2.71828) -> 5.58040
f(3.14159) -> 5.92228

Your answer should be accurate to ±.0001.
Julia, 79 77 38 bytes



I-&gt;sum(x-&gt;(e/x)^x,0:1e-5:min(I,9))/1e5


This is an anonymous function that accepts a numeric value and returns a float. To call it, assign it to a variable.

The approach here is to use a right Riemann sum to approximate the integral, which is given by the following formula:



In our case, a = 0 and b = I, the input. We divide the region of integration into n = 105 discrete portions, so ∆x = 1/n = 10-5. Since this is a constant relative to the sum, we can pull this outside of the sum and simply sum the function evaluations at each point and divide by n.

The function is surprisingly well-behaved (plot from Mathematica):



Since the function evaluates nearly to 0 for inputs greater than about 9, we truncate the input to be I if I is less than 9, or 9 otherwise. This simplifies the calculations we have to do significantly.

Ungolfed code:

function g(I)
    # Define the range over which to sum. We truncate the input
    # at 9 and subdivide the region into 1e5 pieces.
    range = 0:1e-5:min(I,9)

    # Evaluate the function at each of the 1e5 points, sum the
    # results, and divide by the number of points.
    return sum(x -&gt; (e / x)^x, range) / 1e5
end


Saved 39 bytes thanks to Dennis!