# Solving the ODE $f''+f=sin(x)$ using the method of undetermined coefficients

I have found the fundamental solution set of the LHS to be $$J_1=cos(x)$$, $$J_2=sin(x)$$, but then I find the solution set of the RHS to be $$J_3=xcos(x)$$, $$J_4=xsin(x)$$. If I then apply the operator $$A=D^2+1$$ to this solution set to find a particular solution I find $$A(c_1*J_3+c_2*J_4)=(-2c_1+c_2x)*sin(x)+(-c_1x+2c_2)cos(x)=sin(x)$$, which makes it impossible to find a constant value for $$c_1$$ and $$c_2$$. I am probably doing something wrong here, but I can't seem to find my error.

Edit: I did find my error, I forgot adding f at the end and only focussed on the f'' part. Thanks for helping me!

• $AJ_3=-2\sin x$, $AJ_4=2\cos x$. Yes, you're doing something wrong. Write your result of $J_3'$ and $J_3''$ please. Oct 25, 2021 at 14:46
• Your computation of the second derivative is incomplete. $(x\sin x)''=-x\sin x+2\cos x$ etc. Oct 25, 2021 at 14:46
• The method of undetermined coefficients is okay, but I suggest (if you haven't tried it already) that you look into the method of annihilators for problems like this. It might be a little less terse, but it's conceptually way clearer. Oct 25, 2021 at 15:27

$$f''+f=\sin(x).$$ The guess should simply be: $$f_p=x(C_1 \sin x +C_2 \cos x)$$ $$f_p=C_1 x \sin x +C_2 x\cos x$$ But you don't really need the $$C_1x\sin x$$ part. Since $$C_1$$ should be equal to zero.
So just try: $$f_p=C_2 x\cos x$$.
$$\implies f'_p=C_2 \cos x -C_2 x \sin x$$ $$f''_p=-2C_2 \sin x -C_2x \cos x$$ $$f''_p+f_p=-2C_2 \sin x =\sin x$$ $$\implies C_2=-\dfrac 12$$ Therefore: $$f(x)=A \sin x +B \cos x -\dfrac 12 x \cos x.$$
• The guess normally should be $f_p=C_1 x \sin x +C_2 x\cos x$ but then $C_1=0$ b @davidhintzen Oct 25, 2021 at 14:49