A straight rod of length L extends form x=a to x=L+a. The gravitational force on a point mass m at x=0 if the mass per unit length of the rod is (A+Bx2), is
Mass per unit lenght = A + B x2
So the mass of length dx is
d M = dx(A + b x2)
F = a+L∑a Gm (1x2) dx(A + B x2))
= a+L∫aGm(ax2+B)dx
= Gm[Aa−Aa+L+BL]