I'm studying chapter 5 of Discrete-Time Signal Processing 3rd edition by Alan Oppenheim and I'm having serious difficulties understanding how he obtained equation 5.57. For those who don't have this book I tell you that in this part it is analyzing the frequency, phase and group delay of
$$ 1- re^{j \theta} e^{-j \omega} $$
which could either be a pole or a zero depending on whether this factor is in the denominator or numerator of the frequency response. Here r is a random magnitude variable and theta is a random phase variable
So far I have been able to understand how is the phase expression obtained as it is defined as $$\arctan \frac {\Im}{\Re}$$
and
$$ 1- re^{j \theta} e^{-j \omega} = 1- r[ \cos (\theta - \omega) + j \sin(\theta - \omega) ] $$
and as cosine is even and sine is odd
$$ = 1- r[ \cos (\omega- \theta) - j \sin(\omega- \theta) ] = 1- r\cos (\omega- \theta) + j r\sin(\omega- \theta) $$
the resulting phase expression is:
$$ \arctan \frac {r \sin(\omega- \theta)}{1- r \cos (\omega- \theta)}$$
which coincides with equation 5.56 in the book
But when it comes to finding the group delay (which is the negative derivative of this expression) I'm not obtaining what it says in the book. Moreover I introduced the expression in Matlab and I'm obtaining the following result:
According to the book the group delay is;
$$ \frac{r^2 - r\cos (\omega- \theta)}{1 + r^2 - 2r\cos (\omega- \theta)}$$
How did they get there? Can you help me?