# Does Solve work if there are previous outputs in the expression?

Here's what I've done:

Basically I want to differentiate an expression once, then twice and finally use these two results to calculate the expression $$y''-2y'+2y = 4e^x\sin(x)$$ where $y(x) = xe^x(A\cos(x)+B\sin(x))$. My goal is to find constants $A,B$ such that the equality holds. Now using walfram alpha I get that $B=0$ and $A=-2$ as you can see from here:

Where did I go wrong with Mathematica? Or is it a mistake in my way of solving it? (consider that I've already found the solution to the homogeneous equation)

• Wait I've messed up in one of the lines somehow – Euler_Salter Feb 4 '17 at 13:08
• Please do not post images of your work, especially when the images display at a size that make them difficult to read. Please post your actual Mathematica code in the form of text that can be copied and pasted into a Mathematica notebook. Without such, it will be difficult to reproduce your problem and to experiment with possible solutions. – m_goldberg Feb 4 '17 at 14:07

## 1 Answer

Try this:

    y''[x] - 2 y'[x] + 2 y[x] - 4 Exp[x]*Sin[x] /.
y -> (#*Exp[#]*(A*Cos[#] + B*Sin[#]) &) // Simplify

(* 2 E^x (B Cos[x] - (2 + A) Sin[x]) *)


from where B=0 and A=-2.

Have fun!