For multiplications and divisions on arrays, you need to use element-wise operators .*
, ./
, and .^
in the definition of hessianphi
and gradphi
. Otherwise, Matlab will try do do matrix multiplication/division/power, which won't go well.
/aside: searching for the text of the error message will bring up the most likely causes of the error.