13.14 problem 14

13.14.1 Maple step by step solution

Internal problem ID [12797]
Internal file name [OUTPUT/11450_Saturday_November_04_2023_08_47_23_AM_43671262/index.tex]

Book: Ordinary Differential Equations by Charles E. Roberts, Jr. CRC Press. 2010
Section: Chapter 5. The Laplace Transform Method. Exercises 5.2, page 248
Problem number: 14.
ODE order: 3.
ODE degree: 1.

The type(s) of ODE detected by this program : "higher_order_laplace"

Maple gives the following as the ode type

[[_3rd_order, _missing_y]]

\[ \boxed {y^{\prime \prime \prime }+3 y^{\prime \prime }+2 y^{\prime }=x +\cos \left (x \right )} \] With initial conditions \begin {align*} [y \left (0\right ) = 1, y^{\prime }\left (0\right ) = -1, y^{\prime \prime }\left (0\right ) = 2] \end {align*}

Solving using the Laplace transform method. Let \[ \mathcal {L}\left (y\right ) =Y(s) \] Taking the Laplace transform of the ode and using the relations that \begin {align*} \mathcal {L}\left (y^{\prime }\right )&= s Y(s) - y \left (0\right )\\ \mathcal {L}\left (y^{\prime \prime }\right ) &= s^2 Y(s) - y'(0) - s y \left (0\right )\\ \mathcal {L}\left (y^{\prime \prime \prime }\right ) &= s^3 Y(s) - y''(0) - s y'(0) - s^2 y \left (0\right ) \end {align*}

The given ode becomes an algebraic equation in the Laplace domain \[ s^{3} Y \left (s \right )-y^{\prime \prime }\left (0\right )-s y^{\prime }\left (0\right )-s^{2} y \left (0\right )+3 s^{2} Y \left (s \right )-3 y^{\prime }\left (0\right )-3 s y \left (0\right )+2 s Y \left (s \right )-2 y \left (0\right ) = \frac {1}{s^{2}}+\frac {s}{s^{2}+1}\tag {1} \] But the initial conditions are \begin {align*} y \left (0\right )&=1\\ y^{\prime }\left (0\right )&=-1\\ y^{\prime \prime }\left (0\right )&=2 \end {align*}

Substituting these initial conditions in above in Eq (1) gives \[ s^{3} Y \left (s \right )-1-2 s -s^{2}+3 s^{2} Y \left (s \right )+2 s Y \left (s \right ) = \frac {1}{s^{2}}+\frac {s}{s^{2}+1} \] Solving the above equation for \(Y(s)\) results in \[ Y(s) = \frac {s^{6}+2 s^{5}+2 s^{4}+3 s^{3}+2 s^{2}+1}{s^{3} \left (s^{2}+1\right ) \left (s^{2}+3 s +2\right )} \] Applying partial fractions decomposition results in \[ Y(s)= -\frac {1}{2 \left (s +1\right )}+\frac {-\frac {3}{20}-\frac {i}{20}}{s -i}+\frac {-\frac {3}{20}+\frac {i}{20}}{s +i}-\frac {3}{4 s^{2}}+\frac {1}{2 s^{3}}+\frac {11}{8 s}+\frac {17}{40 \left (s +2\right )} \] The inverse Laplace of each term above is now found, which gives \begin {align*} \mathcal {L}^{-1}\left (-\frac {1}{2 \left (s +1\right )}\right ) &= -\frac {{\mathrm e}^{-x}}{2}\\ \mathcal {L}^{-1}\left (\frac {-\frac {3}{20}-\frac {i}{20}}{s -i}\right ) &= \left (-\frac {3}{20}-\frac {i}{20}\right ) {\mathrm e}^{i x}\\ \mathcal {L}^{-1}\left (\frac {-\frac {3}{20}+\frac {i}{20}}{s +i}\right ) &= \left (-\frac {3}{20}+\frac {i}{20}\right ) {\mathrm e}^{-i x}\\ \mathcal {L}^{-1}\left (-\frac {3}{4 s^{2}}\right ) &= -\frac {3 x}{4}\\ \mathcal {L}^{-1}\left (\frac {1}{2 s^{3}}\right ) &= \frac {x^{2}}{4}\\ \mathcal {L}^{-1}\left (\frac {11}{8 s}\right ) &= {\frac {11}{8}}\\ \mathcal {L}^{-1}\left (\frac {17}{40 \left (s +2\right )}\right ) &= \frac {17 \,{\mathrm e}^{-2 x}}{40} \end {align*}

Adding the above results and simplifying gives \[ y=\frac {11}{8}+\frac {x^{2}}{4}-\frac {{\mathrm e}^{-x}}{2}+\frac {17 \,{\mathrm e}^{-2 x}}{40}-\frac {3 x}{4}-\frac {3 \cos \left (x \right )}{10}+\frac {\sin \left (x \right )}{10} \]

Summary

The solution(s) found are the following \begin{align*} \tag{1} y &= \frac {11}{8}+\frac {x^{2}}{4}-\frac {{\mathrm e}^{-x}}{2}+\frac {17 \,{\mathrm e}^{-2 x}}{40}-\frac {3 x}{4}-\frac {3 \cos \left (x \right )}{10}+\frac {\sin \left (x \right )}{10} \\ \end{align*}

Figure 246: Solution plot

Verification of solutions

\[ y = \frac {11}{8}+\frac {x^{2}}{4}-\frac {{\mathrm e}^{-x}}{2}+\frac {17 \,{\mathrm e}^{-2 x}}{40}-\frac {3 x}{4}-\frac {3 \cos \left (x \right )}{10}+\frac {\sin \left (x \right )}{10} \] Verified OK.

13.14.1 Maple step by step solution

\[ \begin {array}{lll} & {} & \textrm {Let's solve}\hspace {3pt} \\ {} & {} & \left [y^{\prime \prime \prime }+3 y^{\prime \prime }+2 y^{\prime }=x +\cos \left (x \right ), y \left (0\right )=1, y^{\prime }{\raise{-0.36em}{\Big |}}{\mstack {}{_{\left \{x \hiderel {=}0\right \}}}}=-1, y^{\prime \prime }{\raise{-0.36em}{\Big |}}{\mstack {}{_{\left \{x \hiderel {=}0\right \}}}}=2\right ] \\ \bullet & {} & \textrm {Highest derivative means the order of the ODE is}\hspace {3pt} 3 \\ {} & {} & y^{\prime \prime \prime } \\ \square & {} & \textrm {Convert linear ODE into a system of first order ODEs}\hspace {3pt} \\ {} & \circ & \textrm {Define new variable}\hspace {3pt} y_{1}\left (x \right ) \\ {} & {} & y_{1}\left (x \right )=y \\ {} & \circ & \textrm {Define new variable}\hspace {3pt} y_{2}\left (x \right ) \\ {} & {} & y_{2}\left (x \right )=y^{\prime } \\ {} & \circ & \textrm {Define new variable}\hspace {3pt} y_{3}\left (x \right ) \\ {} & {} & y_{3}\left (x \right )=y^{\prime \prime } \\ {} & \circ & \textrm {Isolate for}\hspace {3pt} y_{3}^{\prime }\left (x \right )\hspace {3pt}\textrm {using original ODE}\hspace {3pt} \\ {} & {} & y_{3}^{\prime }\left (x \right )=x +\cos \left (x \right )-3 y_{3}\left (x \right )-2 y_{2}\left (x \right ) \\ & {} & \textrm {Convert linear ODE into a system of first order ODEs}\hspace {3pt} \\ {} & {} & \left [y_{2}\left (x \right )=y_{1}^{\prime }\left (x \right ), y_{3}\left (x \right )=y_{2}^{\prime }\left (x \right ), y_{3}^{\prime }\left (x \right )=x +\cos \left (x \right )-3 y_{3}\left (x \right )-2 y_{2}\left (x \right )\right ] \\ \bullet & {} & \textrm {Define vector}\hspace {3pt} \\ {} & {} & {\moverset {\rightarrow }{y}}\left (x \right )=\left [\begin {array}{c} y_{1}\left (x \right ) \\ y_{2}\left (x \right ) \\ y_{3}\left (x \right ) \end {array}\right ] \\ \bullet & {} & \textrm {System to solve}\hspace {3pt} \\ {} & {} & {\moverset {\rightarrow }{y}}^{\prime }\left (x \right )=\left [\begin {array}{ccc} 0 & 1 & 0 \\ 0 & 0 & 1 \\ 0 & -2 & -3 \end {array}\right ]\cdot {\moverset {\rightarrow }{y}}\left (x \right )+\left [\begin {array}{c} 0 \\ 0 \\ x +\cos \left (x \right ) \end {array}\right ] \\ \bullet & {} & \textrm {Define the forcing function}\hspace {3pt} \\ {} & {} & {\moverset {\rightarrow }{f}}\left (x \right )=\left [\begin {array}{c} 0 \\ 0 \\ x +\cos \left (x \right ) \end {array}\right ] \\ \bullet & {} & \textrm {Define the coefficient matrix}\hspace {3pt} \\ {} & {} & A =\left [\begin {array}{ccc} 0 & 1 & 0 \\ 0 & 0 & 1 \\ 0 & -2 & -3 \end {array}\right ] \\ \bullet & {} & \textrm {Rewrite the system as}\hspace {3pt} \\ {} & {} & {\moverset {\rightarrow }{y}}^{\prime }\left (x \right )=A \cdot {\moverset {\rightarrow }{y}}\left (x \right )+{\moverset {\rightarrow }{f}} \\ \bullet & {} & \textrm {To solve the system, find the eigenvalues and eigenvectors of}\hspace {3pt} A \\ \bullet & {} & \textrm {Eigenpairs of}\hspace {3pt} A \\ {} & {} & \left [\left [-2, \left [\begin {array}{c} \frac {1}{4} \\ -\frac {1}{2} \\ 1 \end {array}\right ]\right ], \left [-1, \left [\begin {array}{c} 1 \\ -1 \\ 1 \end {array}\right ]\right ], \left [0, \left [\begin {array}{c} 1 \\ 0 \\ 0 \end {array}\right ]\right ]\right ] \\ \bullet & {} & \textrm {Consider eigenpair}\hspace {3pt} \\ {} & {} & \left [-2, \left [\begin {array}{c} \frac {1}{4} \\ -\frac {1}{2} \\ 1 \end {array}\right ]\right ] \\ \bullet & {} & \textrm {Solution to homogeneous system from eigenpair}\hspace {3pt} \\ {} & {} & {\moverset {\rightarrow }{y}}_{1}={\mathrm e}^{-2 x}\cdot \left [\begin {array}{c} \frac {1}{4} \\ -\frac {1}{2} \\ 1 \end {array}\right ] \\ \bullet & {} & \textrm {Consider eigenpair}\hspace {3pt} \\ {} & {} & \left [-1, \left [\begin {array}{c} 1 \\ -1 \\ 1 \end {array}\right ]\right ] \\ \bullet & {} & \textrm {Solution to homogeneous system from eigenpair}\hspace {3pt} \\ {} & {} & {\moverset {\rightarrow }{y}}_{2}={\mathrm e}^{-x}\cdot \left [\begin {array}{c} 1 \\ -1 \\ 1 \end {array}\right ] \\ \bullet & {} & \textrm {Consider eigenpair}\hspace {3pt} \\ {} & {} & \left [0, \left [\begin {array}{c} 1 \\ 0 \\ 0 \end {array}\right ]\right ] \\ \bullet & {} & \textrm {Solution to homogeneous system from eigenpair}\hspace {3pt} \\ {} & {} & {\moverset {\rightarrow }{y}}_{3}=\left [\begin {array}{c} 1 \\ 0 \\ 0 \end {array}\right ] \\ \bullet & {} & \textrm {General solution of the system of ODEs can be written in terms of the particular solution}\hspace {3pt} {\moverset {\rightarrow }{y}}_{p}\left (x \right ) \\ {} & {} & {\moverset {\rightarrow }{y}}\left (x \right )=c_{1} {\moverset {\rightarrow }{y}}_{1}+c_{2} {\moverset {\rightarrow }{y}}_{2}+c_{3} {\moverset {\rightarrow }{y}}_{3}+{\moverset {\rightarrow }{y}}_{p}\left (x \right ) \\ \square & {} & \textrm {Fundamental matrix}\hspace {3pt} \\ {} & \circ & \textrm {Let}\hspace {3pt} \phi \left (x \right )\hspace {3pt}\textrm {be the matrix whose columns are the independent solutions of the homogeneous system.}\hspace {3pt} \\ {} & {} & \phi \left (x \right )=\left [\begin {array}{ccc} \frac {{\mathrm e}^{-2 x}}{4} & {\mathrm e}^{-x} & 1 \\ -\frac {{\mathrm e}^{-2 x}}{2} & -{\mathrm e}^{-x} & 0 \\ {\mathrm e}^{-2 x} & {\mathrm e}^{-x} & 0 \end {array}\right ] \\ {} & \circ & \textrm {The fundamental matrix,}\hspace {3pt} \Phi \left (x \right )\hspace {3pt}\textrm {is a normalized version of}\hspace {3pt} \phi \left (x \right )\hspace {3pt}\textrm {satisfying}\hspace {3pt} \Phi \left (0\right )=I \hspace {3pt}\textrm {where}\hspace {3pt} I \hspace {3pt}\textrm {is the identity matrix}\hspace {3pt} \\ {} & {} & \Phi \left (x \right )=\phi \left (x \right )\cdot \frac {1}{\phi \left (0\right )} \\ {} & \circ & \textrm {Substitute the value of}\hspace {3pt} \phi \left (x \right )\hspace {3pt}\textrm {and}\hspace {3pt} \phi \left (0\right ) \\ {} & {} & \Phi \left (x \right )=\left [\begin {array}{ccc} \frac {{\mathrm e}^{-2 x}}{4} & {\mathrm e}^{-x} & 1 \\ -\frac {{\mathrm e}^{-2 x}}{2} & -{\mathrm e}^{-x} & 0 \\ {\mathrm e}^{-2 x} & {\mathrm e}^{-x} & 0 \end {array}\right ]\cdot \frac {1}{\left [\begin {array}{ccc} \frac {1}{4} & 1 & 1 \\ -\frac {1}{2} & -1 & 0 \\ 1 & 1 & 0 \end {array}\right ]} \\ {} & \circ & \textrm {Evaluate and simplify to get the fundamental matrix}\hspace {3pt} \\ {} & {} & \Phi \left (x \right )=\left [\begin {array}{ccc} 1 & \frac {{\mathrm e}^{-2 x}}{2}-2 \,{\mathrm e}^{-x}+\frac {3}{2} & \frac {{\mathrm e}^{-2 x}}{2}-{\mathrm e}^{-x}+\frac {1}{2} \\ 0 & -{\mathrm e}^{-2 x}+2 \,{\mathrm e}^{-x} & -{\mathrm e}^{-2 x}+{\mathrm e}^{-x} \\ 0 & 2 \,{\mathrm e}^{-2 x}-2 \,{\mathrm e}^{-x} & 2 \,{\mathrm e}^{-2 x}-{\mathrm e}^{-x} \end {array}\right ] \\ \square & {} & \textrm {Find a particular solution of the system of ODEs using variation of parameters}\hspace {3pt} \\ {} & \circ & \textrm {Let the particular solution be the fundamental matrix multiplied by}\hspace {3pt} {\moverset {\rightarrow }{v}}\left (x \right )\hspace {3pt}\textrm {and solve for}\hspace {3pt} {\moverset {\rightarrow }{v}}\left (x \right ) \\ {} & {} & {\moverset {\rightarrow }{y}}_{p}\left (x \right )=\Phi \left (x \right )\cdot {\moverset {\rightarrow }{v}}\left (x \right ) \\ {} & \circ & \textrm {Take the derivative of the particular solution}\hspace {3pt} \\ {} & {} & {\moverset {\rightarrow }{y}}_{p}^{\prime }\left (x \right )=\Phi ^{\prime }\left (x \right )\cdot {\moverset {\rightarrow }{v}}\left (x \right )+\Phi \left (x \right )\cdot {\moverset {\rightarrow }{v}}^{\prime }\left (x \right ) \\ {} & \circ & \textrm {Substitute particular solution and its derivative into the system of ODEs}\hspace {3pt} \\ {} & {} & \Phi ^{\prime }\left (x \right )\cdot {\moverset {\rightarrow }{v}}\left (x \right )+\Phi \left (x \right )\cdot {\moverset {\rightarrow }{v}}^{\prime }\left (x \right )=A \cdot \Phi \left (x \right )\cdot {\moverset {\rightarrow }{v}}\left (x \right )+{\moverset {\rightarrow }{f}}\left (x \right ) \\ {} & \circ & \textrm {The fundamental matrix has columns that are solutions to the homogeneous system so its derivative follows that of the homogeneous system}\hspace {3pt} \\ {} & {} & A \cdot \Phi \left (x \right )\cdot {\moverset {\rightarrow }{v}}\left (x \right )+\Phi \left (x \right )\cdot {\moverset {\rightarrow }{v}}^{\prime }\left (x \right )=A \cdot \Phi \left (x \right )\cdot {\moverset {\rightarrow }{v}}\left (x \right )+{\moverset {\rightarrow }{f}}\left (x \right ) \\ {} & \circ & \textrm {Cancel like terms}\hspace {3pt} \\ {} & {} & \Phi \left (x \right )\cdot {\moverset {\rightarrow }{v}}^{\prime }\left (x \right )={\moverset {\rightarrow }{f}}\left (x \right ) \\ {} & \circ & \textrm {Multiply by the inverse of the fundamental matrix}\hspace {3pt} \\ {} & {} & {\moverset {\rightarrow }{v}}^{\prime }\left (x \right )=\frac {1}{\Phi \left (x \right )}\cdot {\moverset {\rightarrow }{f}}\left (x \right ) \\ {} & \circ & \textrm {Integrate to solve for}\hspace {3pt} {\moverset {\rightarrow }{v}}\left (x \right ) \\ {} & {} & {\moverset {\rightarrow }{v}}\left (x \right )=\int _{0}^{x}\frac {1}{\Phi \left (s \right )}\cdot {\moverset {\rightarrow }{f}}\left (s \right )d s \\ {} & \circ & \textrm {Plug}\hspace {3pt} {\moverset {\rightarrow }{v}}\left (x \right )\hspace {3pt}\textrm {into the equation for the particular solution}\hspace {3pt} \\ {} & {} & {\moverset {\rightarrow }{y}}_{p}\left (x \right )=\Phi \left (x \right )\cdot \left (\int _{0}^{x}\frac {1}{\Phi \left (s \right )}\cdot {\moverset {\rightarrow }{f}}\left (s \right )d s \right ) \\ {} & \circ & \textrm {Plug in the fundamental matrix and the forcing function and compute}\hspace {3pt} \\ {} & {} & {\moverset {\rightarrow }{y}}_{p}\left (x \right )=\left [\begin {array}{c} \frac {\sin \left (x \right )}{10}-\frac {{\mathrm e}^{-x}}{2}-\frac {3 \,{\mathrm e}^{-2 x}}{40}-\frac {3 x}{4}+\frac {7}{8}+\frac {x^{2}}{4}-\frac {3 \cos \left (x \right )}{10} \\ \frac {{\mathrm e}^{-x}}{2}+\frac {3 \,{\mathrm e}^{-2 x}}{20}+\frac {x}{2}-\frac {3}{4}+\frac {3 \sin \left (x \right )}{10}+\frac {\cos \left (x \right )}{10} \\ -\frac {{\mathrm e}^{-x}}{2}-\frac {3 \,{\mathrm e}^{-2 x}}{10}+\frac {1}{2}-\frac {\sin \left (x \right )}{10}+\frac {3 \cos \left (x \right )}{10} \end {array}\right ] \\ \bullet & {} & \textrm {Plug particular solution back into general solution}\hspace {3pt} \\ {} & {} & {\moverset {\rightarrow }{y}}\left (x \right )=c_{1} {\moverset {\rightarrow }{y}}_{1}+c_{2} {\moverset {\rightarrow }{y}}_{2}+c_{3} {\moverset {\rightarrow }{y}}_{3}+\left [\begin {array}{c} \frac {\sin \left (x \right )}{10}-\frac {{\mathrm e}^{-x}}{2}-\frac {3 \,{\mathrm e}^{-2 x}}{40}-\frac {3 x}{4}+\frac {7}{8}+\frac {x^{2}}{4}-\frac {3 \cos \left (x \right )}{10} \\ \frac {{\mathrm e}^{-x}}{2}+\frac {3 \,{\mathrm e}^{-2 x}}{20}+\frac {x}{2}-\frac {3}{4}+\frac {3 \sin \left (x \right )}{10}+\frac {\cos \left (x \right )}{10} \\ -\frac {{\mathrm e}^{-x}}{2}-\frac {3 \,{\mathrm e}^{-2 x}}{10}+\frac {1}{2}-\frac {\sin \left (x \right )}{10}+\frac {3 \cos \left (x \right )}{10} \end {array}\right ] \\ \bullet & {} & \textrm {First component of the vector is the solution to the ODE}\hspace {3pt} \\ {} & {} & y=\frac {\left (10 c_{1} -3\right ) {\mathrm e}^{-2 x}}{40}+\frac {\left (40 c_{2} -20\right ) {\mathrm e}^{-x}}{40}+\frac {x^{2}}{4}-\frac {3 x}{4}+c_{3} -\frac {3 \cos \left (x \right )}{10}+\frac {\sin \left (x \right )}{10}+\frac {7}{8} \\ \bullet & {} & \textrm {Use the initial condition}\hspace {3pt} y \left (0\right )=1 \\ {} & {} & 1=\frac {c_{1}}{4}+c_{2} +c_{3} \\ \bullet & {} & \textrm {Calculate the 1st derivative of the solution}\hspace {3pt} \\ {} & {} & y^{\prime }=-\frac {\left (10 c_{1} -3\right ) {\mathrm e}^{-2 x}}{20}-\frac {\left (40 c_{2} -20\right ) {\mathrm e}^{-x}}{40}+\frac {x}{2}-\frac {3}{4}+\frac {3 \sin \left (x \right )}{10}+\frac {\cos \left (x \right )}{10} \\ \bullet & {} & \textrm {Use the initial condition}\hspace {3pt} y^{\prime }{\raise{-0.36em}{\Big |}}{\mstack {}{_{\left \{x \hiderel {=}0\right \}}}}=-1 \\ {} & {} & -1=-\frac {c_{1}}{2}-c_{2} \\ \bullet & {} & \textrm {Calculate the 2nd derivative of the solution}\hspace {3pt} \\ {} & {} & y^{\prime \prime }=\frac {\left (10 c_{1} -3\right ) {\mathrm e}^{-2 x}}{10}+\frac {\left (40 c_{2} -20\right ) {\mathrm e}^{-x}}{40}+\frac {1}{2}+\frac {3 \cos \left (x \right )}{10}-\frac {\sin \left (x \right )}{10} \\ \bullet & {} & \textrm {Use the initial condition}\hspace {3pt} y^{\prime \prime }{\raise{-0.36em}{\Big |}}{\mstack {}{_{\left \{x \hiderel {=}0\right \}}}}=2 \\ {} & {} & 2=c_{1} +c_{2} \\ \bullet & {} & \textrm {Solve for the unknown coefficients}\hspace {3pt} \\ {} & {} & \left \{c_{1} =2, c_{2} =0, c_{3} =\frac {1}{2}\right \} \\ \bullet & {} & \textrm {Solution to the IVP}\hspace {3pt} \\ {} & {} & y=\frac {11}{8}+\frac {x^{2}}{4}-\frac {{\mathrm e}^{-x}}{2}+\frac {17 \,{\mathrm e}^{-2 x}}{40}-\frac {3 x}{4}-\frac {3 \cos \left (x \right )}{10}+\frac {\sin \left (x \right )}{10} \end {array} \]

Maple trace

`Methods for third order ODEs: 
--- Trying classification methods --- 
trying a quadrature 
trying high order exact linear fully integrable 
trying differential order: 3; linear nonhomogeneous with symmetry [0,1] 
-> Calling odsolve with the ODE`, diff(diff(_b(_a), _a), _a) = -3*(diff(_b(_a), _a))-2*_b(_a)+_a+cos(_a), _b(_a)`   *** Sublevel 2 * 
   Methods for second order ODEs: 
   --- Trying classification methods --- 
   trying a quadrature 
   trying high order exact linear fully integrable 
   trying differential order: 2; linear nonhomogeneous with symmetry [0,1] 
   trying a double symmetry of the form [xi=0, eta=F(x)] 
   <- double symmetry of the form [xi=0, eta=F(x)] successful 
<- differential order: 3; linear nonhomogeneous with symmetry [0,1] successful`
 

Solution by Maple

Time used: 5.36 (sec). Leaf size: 34

dsolve([diff(y(x),x$3)+3*diff(y(x),x$2)+2*diff(y(x),x)=x+cos(x),y(0) = 1, D(y)(0) = -1, (D@@2)(y)(0) = 2],y(x), singsol=all)
 

\[ y \left (x \right ) = -\frac {3 \cos \left (x \right )}{10}+\frac {\sin \left (x \right )}{10}-\frac {{\mathrm e}^{-x}}{2}-\frac {3 x}{4}+\frac {x^{2}}{4}+\frac {17 \,{\mathrm e}^{-2 x}}{40}+\frac {11}{8} \]

Solution by Mathematica

Time used: 0.565 (sec). Leaf size: 41

DSolve[{y'''[x]+3*y''[x]+2*y'[x]==x+Cos[x],{y[0]==1,y'[0]==-1,y''[0]==2}},y[x],x,IncludeSingularSolutions -> True]
 

\[ y(x)\to \frac {1}{40} \left (10 x^2-30 x+17 e^{-2 x}-20 e^{-x}+4 \sin (x)-12 \cos (x)+55\right ) \]