Solution to problem 1D