Array issue with optimzing a function with quadgk

Do you have any tips on how to do this?