Code and plot for the third exercise.