75.18.8 problem 597

Internal problem ID [17017]
Book : A book of problems in ordinary differential equations. M.L. KRASNOV, A.L. KISELYOV, G.I. MARKARENKO. MIR, MOSCOW. 1983
Section : Chapter 2 (Higher order ODEs). Section 15.3 Nonhomogeneous linear equations with constant coefficients. Initial value problem. Exercises page 140
Problem number : 597
Date solved : Thursday, March 13, 2025 at 09:10:04 AM
CAS classification : [[_2nd_order, _linear, _nonhomogeneous]]

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

With initial conditions

\begin{align*} y \left (0\right )&=1\\ y^{\prime }\left (0\right )&=0 \end{align*}

Maple. Time used: 0.016 (sec). Leaf size: 11
ode:=diff(diff(y(x),x),x)+y(x) = 2*cos(x); 
ic:=y(0) = 1, D(y)(0) = 0; 
dsolve([ode,ic],y(x), singsol=all);
 
\[ y = \cos \left (x \right )+x \sin \left (x \right ) \]
Mathematica. Time used: 0.025 (sec). Leaf size: 45
ode=D[y[x],{x,2}]+y[x]==2*Cos[x]; 
ic={y[0]==1,Derivative[1][y][0] ==0}; 
DSolve[{ode,ic},y[x],x,IncludeSingularSolutions->True]
 
\[ y(x)\to -\sin (x) \int _1^02 \cos ^2(K[1])dK[1]+\sin (x) \int _1^x2 \cos ^2(K[1])dK[1]+\cos ^3(x) \]
Sympy. Time used: 0.083 (sec). Leaf size: 10
from sympy import * 
x = symbols("x") 
y = Function("y") 
ode = Eq(y(x) - 2*cos(x) + Derivative(y(x), (x, 2)),0) 
ics = {y(0): 1, Subs(Derivative(y(x), x), x, 0): 0} 
dsolve(ode,func=y(x),ics=ics)
 
\[ y{\left (x \right )} = x \sin {\left (x \right )} + \cos {\left (x \right )} \]