Can you deeply explain how to do problems like this

Given a function f(x), to find the average rate of change over the interval:
[tex]a\leq x\leq b[/tex]we have the following expression:
[tex]\frac{f(b)-f(a)}{b-a}[/tex]in this case, we have the following interval:
this means that a = -9 and b =-2. Now, lets find g(-9) and g(-2):
[tex]\begin{gathered} g(-9)=(-9)^2+5(-9)+1=81-45+1=37 \\ g(-2)=(-2)^2+5(-2)+1=-5 \end{gathered}[/tex]then, using the formula for the average rate of change for the function g(x), we get:
[tex]\frac{g(b)-g(a)}{b-a}=\frac{g(-2)-g(-9)}{-2-(-9)}=\frac{-5-37}{-2+9}=-\frac{42}{7}=-6[/tex]therefore, the rate of change is -6