Solved by albanD in post #4 
              
              
                Your full function here is: 
f(x) = ( sum_i (xi+2)^2 * 3 ) / size(x) = (sum_i (xi+2)^2 * 3 ) / 4 
df(x)/dxj = 2 * (xj + 2) *3 / 4 
given that you start with xi = 1 for all i. 
the gradients you expect with no scaling is: 2 * (1 + 2) *3 / 4 = 4.5 
So if you multiply the result by 2, you get 9 as expe…