62.27.1 problem Ex 1

Internal problem ID [12868]
Book : An elementary treatise on differential equations by Abraham Cohen. DC heath publishers. 1906
Section : Chapter VII, Linear differential equations with constant coefficients. Article 50. Method of undetermined coefficients. Page 107
Problem number : Ex 1
Date solved : Monday, March 31, 2025 at 07:23:07 AM
CAS classification : [[_2nd_order, _linear, _nonhomogeneous]]

\begin{align*} y^{\prime \prime }+4 y&=x^{2}+\cos \left (x \right ) \end{align*}

Maple. Time used: 0.003 (sec). Leaf size: 27
ode:=diff(diff(y(x),x),x)+4*y(x) = x^2+cos(x); 
dsolve(ode,y(x), singsol=all);
 
\[ y = \sin \left (2 x \right ) c_2 +\cos \left (2 x \right ) c_1 +\frac {x^{2}}{4}-\frac {1}{8}+\frac {\cos \left (x \right )}{3} \]
Mathematica. Time used: 0.3 (sec). Leaf size: 77
ode=D[y[x],{x,2}]+4*y[x]==x^2+Cos[x]; 
ic={}; 
DSolve[{ode,ic},y[x],x,IncludeSingularSolutions->True]
 
\[ y(x)\to \cos (2 x) \int _1^x-\cos (K[1]) \left (K[1]^2+\cos (K[1])\right ) \sin (K[1])dK[1]+\sin (2 x) \int _1^x\frac {1}{2} \cos (2 K[2]) \left (K[2]^2+\cos (K[2])\right )dK[2]+c_1 \cos (2 x)+c_2 \sin (2 x) \]
Sympy. Time used: 0.091 (sec). Leaf size: 29
from sympy import * 
x = symbols("x") 
y = Function("y") 
ode = Eq(-x**2 + 4*y(x) - cos(x) + Derivative(y(x), (x, 2)),0) 
ics = {} 
dsolve(ode,func=y(x),ics=ics)
 
\[ y{\left (x \right )} = C_{1} \sin {\left (2 x \right )} + C_{2} \cos {\left (2 x \right )} + \frac {x^{2}}{4} + \frac {\cos {\left (x \right )}}{3} - \frac {1}{8} \]