Code and plot for plot3.