Jensen type weighted inequalities for functions of selfadjoint and unitary operators