Code and plot for the fourth exercise.