Code and plot for 6th question