# Integration by parts for FEM

I am trying to teach myself the basics of FEM but am having trouble with the the manipulations involved. For instance, Example 5.5 of Hutton's "Fundamentals of Finite Element Analysis" provides a worked solution of
$$x{d^2y\over dx^2}+{dy\over dx} -4x=0 \qquad 1\le x \le 2 \qquad y(1)=y(2)=0$$ using a hat-type trial function: $y(x)=y_1.N_1+y_2.N_2=y_1{x_2-x\over x_2-x_1}+y_2{x-x_1\over x_2-x_1}$

The working given, relies on the insight that the equation is equivalent to $${d\over dx}\left(x{dy\over dx}\right)-4x=0$$ giving the element equation $$\int_{x_1}^{x_2}N_i\left[{d\over dx}\left(x{dy\over dx}\right)-4x\right]=0 \qquad i=1, 2$$ Integration by parts, substitution and rearrangement then gives $$N_ix{dy\over dx}\biggl|_{x_1}^{x_2}-\int_{x_1}^{x_2}x{dN_i\over dx}.{dy \over dx}dx-4\int_{x_1}^{x_2}x.N_idx=0$$ All this I can follow; my problem comes if I miss that insight that leads to the second form of the subject DE above. Then working from the original form of the DE, I get an element equation like $$x.N_i{dy\over dx}\biggl|_{x_1}^{x_2}-\int_{x_1}^{x_2}{d(N_i.x)\over dx}{dy\over dx}dx+\int_{x_1}^{x_2}N_i.{dy\over dx}dx-4\int_{x_1}^{x_2}x.N_idx=0$$ and try as I may, I cannot get to a form equivalent to the first approach above. I suspect I am making a basic error in the integration or other part of the manipulation. Can someone please guide me out of my confusion?

If you use product rule of differentiation on $N_i \cdot x$, you can simplify the second and third terms in the last equation of your post to
$$-\int_{x_1}^{x_2}{d(N_i.x)\over dx}{dy\over dx}dx+\int_{x_1}^{x_2}N_i {dy\over dx}dx = - \int_{x_1}^{x_2}x{dN_i\over dx}{dy\over dx}dx - \int_{x_1}^{x_2} N_i {dy\over dx}dx+\int_{x_1}^{x_2}N_i{dy\over dx}dx = - \int_{x_1}^{x_2}x{dN_i\over dx}{dy\over dx}dx .$$