Code and plot for 3rd question