6
$\begingroup$

I bought the Home Edition of Mathematica online 0.5 G of memory and costs \$150 per year. When I calculated the median of outputs from $[0,1]$ with an interval of $.000001$ I ended up with the follwoing

Median[Table[2^x-x,{x,0,1,.000001}]]
0.935553527528773

Then I tried a smaller interval of $.0000001$ and got.

Median[Table[2^x-x,{x,0,1,.0000001}]
Cloud::memlimit :  *This computation has exceeded the memory limit for your plan*

I had limited knowledge of mathematica and am taking a college course on its next year. I tried the documentations but found little. Is there a way of calculating interval up to and smaller than seven digits without switching to the standard edition that costs \$950 per year?

$\endgroup$
  • 1
    $\begingroup$ Most calculations can be done with limited memory (writing intermediate results to disk) if you are prepared to put enough effort into writing the software. $\endgroup$ – mikado Jun 18 '16 at 15:48
  • 1
    $\begingroup$ @Feyre the function 2^x-x is not monotonic on [0 1] $\endgroup$ – mikado Jun 18 '16 at 15:50
  • 3
    $\begingroup$ You may be able to compute the median of a large set by reexpressing as a minimization problem e.g. Minimize[Sum[Abs[(2^x - x) - y], {x, 0, 1, 0.00001}], y] $\endgroup$ – mikado Jun 18 '16 at 15:54
  • 1
    $\begingroup$ I see that the code in the question has been changed so my comments regarding memory are now invalid. $\endgroup$ – Mr.Wizard Jun 18 '16 at 15:59
  • 2
    $\begingroup$ FWIW, the answer is Root[{-(Log[2]/2) + ProductLog[-2^-#1 Log[2]] - ProductLog[-1, -2^-#1 Log[2]] &, 0.935553478022935551757231992253}]. $\endgroup$ – Chip Hurst Jun 18 '16 at 16:07
7
$\begingroup$

As mentioned in the comments, here's the answer to how I got the median.

I found the value $y$ that minimized

$$ f(y) = \int_0^1 \left| 2^x-x-y \right| dx. $$

First, to break up the absolute value in the integrand, I solved for when $2^x = y$:

Solve[(2^x - x) == y && 9/10 < y < 1, x, Reals]

enter image description here

Then I integrated and found where $f'(y) = 0$:

int = Integrate[2^x - x - y, {x, 0, b1}] 
      - Integrate[2^x - x - y, {x, b1, b2}] 
      + Integrate[2^x - x - y, {x, b2, 1}];

Solve[D[int, y] == 0 && 9/10 < y < 1, y, Reals]
{{y -> Root[{-(Log[2]/2) + ProductLog[-2^-#1 Log[2]] - 
   ProductLog[-1, -2^-#1 Log[2]] &, 0.935553478022935551757231992253}]}}

I decided to keep things symbolic in hopes of a nice looking answer. A numeric adaptation would probably be much easier.

$\endgroup$
  • $\begingroup$ That is amazing! Is there a mathematical textbook on this or is it simply logic? $\endgroup$ – Arbuja Jun 18 '16 at 16:26
  • $\begingroup$ Well I essentially just did what mikado did, but in integral form. It seems like it would be the median, but I have no source... $\endgroup$ – Chip Hurst Jun 18 '16 at 16:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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