2.20.4 Problem 37

2.20.4.1 Solved using first_order_ode_riccati
2.20.4.2 Maple
2.20.4.3 Mathematica
2.20.4.4 Sympy

Internal problem ID [13484]
Book : Handbook of exact solutions for ordinary differential equations. By Polyanin and Zaitsev. Second edition
Section : Chapter 1, section 1.2. Riccati Equation. subsection 1.2.8-2. Equations containing arbitrary functions and their derivatives.
Problem number : 37
Date solved : Wednesday, December 31, 2025 at 09:50:39 PM
CAS classification : [[_1st_order, `_with_symmetry_[F(x),G(x)]`], _Riccati]

2.20.4.1 Solved using first_order_ode_riccati

16.357 (sec)

Entering first order ode riccati solver

\begin{align*} y^{\prime }&=g \left (x \right ) \left (y-f \left (x \right )\right )^{2}+f^{\prime }\left (x \right ) \\ \end{align*}
In canonical form the ODE is
\begin{align*} y' &= F(x,y)\\ &= f \left (x \right )^{2} g \left (x \right )-2 f \left (x \right ) g \left (x \right ) y+g \left (x \right ) y^{2}+f^{\prime }\left (x \right ) \end{align*}

This is a Riccati ODE. Comparing the ODE to solve

\[ y' = \textit {the\_rhs} \]
With Riccati ODE standard form
\[ y' = f_0(x)+ f_1(x)y+f_2(x)y^{2} \]
Shows that \(f_0(x)=f \left (x \right )^{2} g \left (x \right )+f^{\prime }\left (x \right )\), \(f_1(x)=-2 f \left (x \right ) g \left (x \right )\) and \(f_2(x)=g \left (x \right )\). Let
\begin{align*} y &= \frac {-u'}{f_2 u} \\ &= \frac {-u'}{u g \left (x \right )} \tag {1} \end{align*}

Using the above substitution in the given ODE results (after some simplification) in a second order ODE to solve for \(u(x)\) which is

\begin{align*} f_2 u''(x) -\left ( f_2' + f_1 f_2 \right ) u'(x) + f_2^2 f_0 u(x) &= 0 \tag {2} \end{align*}

But

\begin{align*} f_2' &=g^{\prime }\left (x \right )\\ f_1 f_2 &=-2 f \left (x \right ) g \left (x \right )^{2}\\ f_2^2 f_0 &=g \left (x \right )^{2} \left (f \left (x \right )^{2} g \left (x \right )+f^{\prime }\left (x \right )\right ) \end{align*}

Substituting the above terms back in equation (2) gives

\[ g \left (x \right ) u^{\prime \prime }\left (x \right )-\left (g^{\prime }\left (x \right )-2 f \left (x \right ) g \left (x \right )^{2}\right ) u^{\prime }\left (x \right )+g \left (x \right )^{2} \left (f \left (x \right )^{2} g \left (x \right )+f^{\prime }\left (x \right )\right ) u \left (x \right ) = 0 \]
Unable to solve. Will ask Maple to solve this ode now.

The solution for \(u \left (x \right )\) is

\begin{equation} \tag{3} u \left (x \right ) = \left (c_1 +\int g \left (x \right )d x \right ) {\mathrm e}^{\int -f \left (x \right ) g \left (x \right )d x} c_2 \end{equation}
Taking derivative gives
\begin{equation} \tag{4} u^{\prime }\left (x \right ) = g \left (x \right ) {\mathrm e}^{\int -f \left (x \right ) g \left (x \right )d x} c_2 -\left (c_1 +\int g \left (x \right )d x \right ) f \left (x \right ) g \left (x \right ) {\mathrm e}^{\int -f \left (x \right ) g \left (x \right )d x} c_2 \end{equation}
Substituting equations (3,4) into (1) results in
\begin{align*} y &= \frac {-u'}{f_2 u} \\ y &= \frac {-u'}{u g \left (x \right )} \\ y &= -\frac {\left (g \left (x \right ) {\mathrm e}^{\int -f \left (x \right ) g \left (x \right )d x} c_2 -\left (c_1 +\int g \left (x \right )d x \right ) f \left (x \right ) g \left (x \right ) {\mathrm e}^{\int -f \left (x \right ) g \left (x \right )d x} c_2 \right ) {\mathrm e}^{\int f \left (x \right ) g \left (x \right )d x}}{g \left (x \right ) \left (c_1 +\int g \left (x \right )d x \right ) c_2} \\ \end{align*}
Doing change of constants, the above solution becomes
\[ y = -\frac {\left (g \left (x \right ) {\mathrm e}^{\int -f \left (x \right ) g \left (x \right )d x} c_3 -\left (1+\int g \left (x \right )d x \right ) f \left (x \right ) g \left (x \right ) {\mathrm e}^{\int -f \left (x \right ) g \left (x \right )d x} c_3 \right ) {\mathrm e}^{\int f \left (x \right ) g \left (x \right )d x}}{g \left (x \right ) \left (1+\int g \left (x \right )d x \right ) c_3} \]

Summary of solutions found

\begin{align*} y &= -\frac {\left (g \left (x \right ) {\mathrm e}^{\int -f \left (x \right ) g \left (x \right )d x} c_3 -\left (1+\int g \left (x \right )d x \right ) f \left (x \right ) g \left (x \right ) {\mathrm e}^{\int -f \left (x \right ) g \left (x \right )d x} c_3 \right ) {\mathrm e}^{\int f \left (x \right ) g \left (x \right )d x}}{g \left (x \right ) \left (1+\int g \left (x \right )d x \right ) c_3} \\ \end{align*}
2.20.4.2 Maple. Time used: 0.004 (sec). Leaf size: 17
ode:=diff(y(x),x) = g(x)*(y(x)-f(x))^2+diff(f(x),x); 
dsolve(ode,y(x), singsol=all);
 
\[ y = f \left (x \right )+\frac {1}{c_1 -\int g \left (x \right )d x} \]

Maple trace

Methods for first order ODEs: 
--- Trying classification methods --- 
trying a quadrature 
trying 1st order linear 
trying Bernoulli 
trying separable 
trying inverse linear 
trying homogeneous types: 
trying Chini 
differential order: 1; looking for linear symmetries 
trying exact 
Looking for potential symmetries 
trying Riccati 
trying Riccati sub-methods: 
   <- Riccati particular case Kamke (d) successful
 

Maple step by step

\[ \begin {array}{lll} & {} & \textrm {Let's solve}\hspace {3pt} \\ {} & {} & \frac {d}{d x}y \left (x \right )=g \left (x \right ) \left (y \left (x \right )-f \left (x \right )\right )^{2}+\frac {d}{d x}f \left (x \right ) \\ \bullet & {} & \textrm {Highest derivative means the order of the ODE is}\hspace {3pt} 1 \\ {} & {} & \frac {d}{d x}y \left (x \right ) \\ \bullet & {} & \textrm {Solve for the highest derivative}\hspace {3pt} \\ {} & {} & \frac {d}{d x}y \left (x \right )=g \left (x \right ) \left (y \left (x \right )-f \left (x \right )\right )^{2}+\frac {d}{d x}f \left (x \right ) \end {array} \]
2.20.4.3 Mathematica. Time used: 0.138 (sec). Leaf size: 31
ode=D[y[x],x]==g[x]*(y[x]-f[x])^2+D[ f[x],x]; 
ic={}; 
DSolve[{ode,ic},y[x],x,IncludeSingularSolutions->True]
 
\begin{align*} y(x)&\to f(x)+\frac {1}{-\int _1^xg(K[2])dK[2]+c_1}\\ y(x)&\to f(x) \end{align*}
2.20.4.4 Sympy
from sympy import * 
x = symbols("x") 
y = Function("y") 
f = Function("f") 
g = Function("g") 
ode = Eq(-(-f(x) + y(x))**2*g(x) - Derivative(f(x), x) + Derivative(y(x), x),0) 
ics = {} 
dsolve(ode,func=y(x),ics=ics)
 
IndexError : Index out of range: a[1]