Code and plot for 4th question