dirac() function gives infinity when its input is 1. It can cause issues in the function fun, making it impossible to integrate
fun = @(x) (-(k*dirac(x-1) + (1-k)*dirac(x+1)).*log(1./(k*dirac(x-1) + (1-k)*dirac(x+1))));
Can you show us the actual problem ad whar are you trying to optimize?