18.1.22 problem Problem 14.26

Internal problem ID [3478]
Book : Mathematical methods for physics and engineering, Riley, Hobson, Bence, second edition, 2002
Section : Chapter 14, First order ordinary differential equations. 14.4 Exercises, page 490
Problem number : Problem 14.26
Date solved : Tuesday, March 04, 2025 at 04:41:42 PM
CAS classification : [_linear]

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

With initial conditions

\begin{align*} y \left (\frac {\pi }{2}\right )&=1 \end{align*}

Maple. Time used: 0.015 (sec). Leaf size: 10
ode:=diff(y(x),x)*sin(x)+2*y(x)*cos(x) = 1; 
ic:=y(1/2*Pi) = 1; 
dsolve([ode,ic],y(x), singsol=all);
 
\[ y \left (x \right ) = \frac {1}{\cos \left (x \right )+1} \]
Mathematica. Time used: 0.036 (sec). Leaf size: 14
ode=Sin[x]*D[y[x],x]+2*y[x]*Cos[x]==1; 
ic=y[Pi/2]==1; 
DSolve[{ode,ic},y[x],x,IncludeSingularSolutions->True]
 
\[ y(x)\to \tan \left (\frac {x}{2}\right ) \csc (x) \]
Sympy. Time used: 0.327 (sec). Leaf size: 12
from sympy import * 
x = symbols("x") 
y = Function("y") 
ode = Eq(2*y(x)*cos(x) + sin(x)*Derivative(y(x), x) - 1,0) 
ics = {y(pi/2): 1} 
dsolve(ode,func=y(x),ics=ics)
 
\[ y{\left (x \right )} = \frac {1 - \cos {\left (x \right )}}{\sin ^{2}{\left (x \right )}} \]