if f ~= k
You need to declare W as complex hermitian. in order for W >= 0 to be treated as a smidefinite constraint. Or just declare W as hermitian semidefinite, and then you don’t even need W >= 0.
Perhaps that will make your already encountered error go away, even without the real(). Or maybe placing parentheses around A1'*A which couldn’t hurt., and might help. You can use the real() if you want to.