In a bit more detail: take the integral of x^3 (the volume function) from 1 to 5 and you get 5^4/4 - 1^4/4 = 624/4 = 156. Then we divide by the length of the line segment (4) to get 39.
If the side lengths have to be integers, then it's just (1 + 8 + 27 + 64 + 125)/5 = 45 inches.
Edit: corrected division mistake, thanks to dxbydt
Edit 2: and corrected a second mistake thanks to tzs.
Well, one of the mistakes:
> If the side lengths have to be integers, then it's just (1 + 8 + 27 + 125)/4 = 40.25 inches
If I'm not mistaken, 4 is an integer, and so should not have cruelly snubbed when you sent out invitations to your summation of the cubes of the integers from 1 to 5. Sure, 4 is not a cool integer like the others in 1 to 5...he's got a reputation as a square, but that doesn't mean he doesn't have feelings.
But seriously, you write rather well on Quora & I'm sure the crowd would want to know what happens to the volume were you to choose a normal distribution instead of a uniform, so I hope you respond.
Let X be a random variable and g be any function.
If X is continuous, then the expectation of g(X) is defined as,
E[g(X)] = \int_−∞^∞ g(x)f(x) dx,
where f is the probability density function of X.
---
For us, with mean 3 and sigma 2/3, f = 3/2 e^(-9/8 (x-3)^2)/sqrt(2 π)
We need to integrate numerically; using Wolfram [1] we get an estimate of 30.8099.
If we ask for the expected value over the entire distribution we get 31.
[0] http://imai.princeton.edu/teaching/files/Expectation.pdf
[1] http://www.wolframalpha.com/input/?i=integrate+3%2F2+e%5E%28...
[2] http://www.wolframalpha.com/input/?i=expected+value+of+x%5E3...
1/3 of the cubes have volume 1, 1/3 have volume 27, and 1/3 have volume 125. The expected value of the volume is 51. Think about why it is 51, not 27, and you'll see why it is not 27 for the continuous case.
In general, if you have a random variable X, and some function of that random variable, f(X), then it is NOT true that expected value of f(X) = f(expected value of X).
from random import random
sum([(random()*4+1)**3 for x in xrange(1000000)])/1000000
=> ~39
Weird. sum(random.uniform(1, 5)**3 for i in range(10000)) / 10000
Many people don't know that the random module allows to sample from many distributions directly without having to construct your own.
aside, I recently interviewed a candidate for a "Big Data" position. He got quite chatty about Kolmogorov & Measure Theory, so I quickly cooked up an interesting problem to relax his nerves. I opened the interview with "If the side of a cube comes from a uniform distribution between 1 and 5 inches, what's the expected volume of the cube ?" I thought he'll give me the answer in 10 seconds & we'll move on but instead he was completely stumped & just stared blankly. I asked him to use the whiteboard but he simply drew a cube and wrote a^3, a~[1,5], and then went back to staring at it. Finally after 10 minutes of pin-drop silence, my partner, a non-math guy, took over the interview & asked him some Hadoop related technology questions & he started speaking again.