problem 9, pretty much an analytical solution but it could be tidied up a bit