Firstly we remind ourselves of the integration by parts formula. The formula used to integrate u dv/dx with respect to x = uv - the integral of v du/dx with respect to x.
So the first thing we have to decide is which part of our expression (x or sin(3x)) we will assign to be v, and which part we will assign to be du/dx. When x is involved it is often easiest to assign u to it, because we differentiate u, and so x will just become 1 and will be easier to handle.
So we write out u = x, du/dx = 1. And then dv/dx = sin(3x), so we work backwards and integrate sin(3x) to find v. Our thought process to integrate sin(3x) goes like this: we need to find what goes to sin(3x) when differentiated. We know that - cos(x) goes to sin(x) when differentiated. But we need sin(3x) not sin(x). So we then try -cos(3x). But this, by the chain rule goes to 3sin(3x). So we know that we have to put 1/3 in front of the -cos(x). Therefore we have found that v = -1/3 cos(3x).
We can then start plugging in these values into our integration by parts equation. So the integral = uv - the integral of v du/dx. So the integral = -(1/3)x cos(3x) - the integral of -1/3 cos(3x). So our last step is integrating -1/3 cos(3x). We do this in a similar way to integrating sin(3x). We have to find what differentiates to give -1/3 cos(3x). We know that sin(x) differentiates to cos(x), so - sin(x) will differentiate to -cos(x). This is our first step. We then must take into account that we want 3x not x, so we differentiate - sin(3x) which gives -3 cos(3x). So everything will increase by a factor of 3. We notice that we want to have a constant of 1/3 left so the value of the constant in front of - sin(3x) must be 1/9, so that when multiplied by 3, we are left with -1/3 cos(3x). Because we have to minus -1/3 cos(3x) in our equation by parts formula, the subtraction signs cancel out.
So we have found that the integral of x sin(3x) is -(1/3)x cos (3x) + (1/9) sin(3x) + C.
Make sure to not forget the constant!