Code and plot for the second exercise.