2.1.25 Problem 5

Solved as first order linear ode
Maple step by step solution
Maple trace
Maple dsolve solution
Mathematica DSolve solution
Sympy solution

Internal problem ID [18503]
Book : Elementary Differential Equations. By R.L.E. Schwarzenberger. Chapman and Hall. London. First Edition (1969)
Section : Chapter 3. Solutions of first-order equations. Exercises at page 47
Problem number : 5
Date solved : Saturday, February 22, 2025 at 09:18:09 PM
CAS classification : [_linear]

Solve

\begin{align*} t x^{\prime }+x g \left (t \right )&=h \left (t \right ) \end{align*}

Solved as first order linear ode

Time used: 0.259 (sec)

In canonical form a linear first order is

\begin{align*} x^{\prime } + q(t)x &= p(t) \end{align*}

Comparing the above to the given ode shows that

\begin{align*} q(t) &=\frac {g \left (t \right )}{t}\\ p(t) &=\frac {h \left (t \right )}{t} \end{align*}

The integrating factor \(\mu \) is

\[ \mu = {\mathrm e}^{\int \frac {g \left (t \right )}{t}d t} \]

Therefore the solution is

\[ x = \left (\int \frac {h \left (t \right ) {\mathrm e}^{\int \frac {g \left (t \right )}{t}d t}}{t}d t +c_1 \right ) {\mathrm e}^{-\int \frac {g \left (t \right )}{t}d t} \]

Summary of solutions found

\begin{align*} x &= \left (\int \frac {h \left (t \right ) {\mathrm e}^{\int \frac {g \left (t \right )}{t}d t}}{t}d t +c_1 \right ) {\mathrm e}^{-\int \frac {g \left (t \right )}{t}d t} \\ \end{align*}

Maple step by step solution
\[ \begin {array}{lll} & {} & \textrm {Let's solve}\hspace {3pt} \\ {} & {} & t x^{\prime }+x g \left (t \right )=h \left (t \right ) \\ \bullet & {} & \textrm {Highest derivative means the order of the ODE is}\hspace {3pt} 1 \\ {} & {} & x^{\prime } \\ \bullet & {} & \textrm {Solve for the highest derivative}\hspace {3pt} \\ {} & {} & x^{\prime }=\frac {-x g \left (t \right )+h \left (t \right )}{t} \\ \bullet & {} & \textrm {Collect w.r.t.}\hspace {3pt} x\hspace {3pt}\textrm {and simplify}\hspace {3pt} \\ {} & {} & x^{\prime }=-\frac {x g \left (t \right )}{t}+\frac {h \left (t \right )}{t} \\ \bullet & {} & \textrm {Group terms with}\hspace {3pt} x\hspace {3pt}\textrm {on the lhs of the ODE and the rest on the rhs of the ODE}\hspace {3pt} \\ {} & {} & x^{\prime }+\frac {x g \left (t \right )}{t}=\frac {h \left (t \right )}{t} \\ \bullet & {} & \textrm {The ODE is linear; multiply by an integrating factor}\hspace {3pt} \mu \left (t \right ) \\ {} & {} & \mu \left (t \right ) \left (x^{\prime }+\frac {x g \left (t \right )}{t}\right )=\frac {\mu \left (t \right ) h \left (t \right )}{t} \\ \bullet & {} & \textrm {Assume the lhs of the ODE is the total derivative}\hspace {3pt} \frac {d}{d t}\left (x \mu \left (t \right )\right ) \\ {} & {} & \mu \left (t \right ) \left (x^{\prime }+\frac {x g \left (t \right )}{t}\right )=x^{\prime } \mu \left (t \right )+x \mu ^{\prime }\left (t \right ) \\ \bullet & {} & \textrm {Isolate}\hspace {3pt} \mu ^{\prime }\left (t \right ) \\ {} & {} & \mu ^{\prime }\left (t \right )=\frac {\mu \left (t \right ) g \left (t \right )}{t} \\ \bullet & {} & \textrm {Solve to find the integrating factor}\hspace {3pt} \\ {} & {} & \mu \left (t \right )={\mathrm e}^{\int \frac {g \left (t \right )}{t}d t} \\ \bullet & {} & \textrm {Integrate both sides with respect to}\hspace {3pt} t \\ {} & {} & \int \left (\frac {d}{d t}\left (x \mu \left (t \right )\right )\right )d t =\int \frac {\mu \left (t \right ) h \left (t \right )}{t}d t +\mathit {C1} \\ \bullet & {} & \textrm {Evaluate the integral on the lhs}\hspace {3pt} \\ {} & {} & x \mu \left (t \right )=\int \frac {\mu \left (t \right ) h \left (t \right )}{t}d t +\mathit {C1} \\ \bullet & {} & \textrm {Solve for}\hspace {3pt} x \\ {} & {} & x=\frac {\int \frac {\mu \left (t \right ) h \left (t \right )}{t}d t +\mathit {C1}}{\mu \left (t \right )} \\ \bullet & {} & \textrm {Substitute}\hspace {3pt} \mu \left (t \right )={\mathrm e}^{\int \frac {g \left (t \right )}{t}d t} \\ {} & {} & x=\frac {\int \frac {h \left (t \right ) {\mathrm e}^{\int \frac {g \left (t \right )}{t}d t}}{t}d t +\mathit {C1}}{{\mathrm e}^{\int \frac {g \left (t \right )}{t}d t}} \\ \bullet & {} & \textrm {Simplify}\hspace {3pt} \\ {} & {} & x=\left (\int \frac {h \left (t \right ) {\mathrm e}^{\int \frac {g \left (t \right )}{t}d t}}{t}d t +\mathit {C1} \right ) {\mathrm e}^{-\int \frac {g \left (t \right )}{t}d t} \end {array} \]

Maple trace
`Methods for first order ODEs: 
--- Trying classification methods --- 
trying a quadrature 
trying 1st order linear 
<- 1st order linear successful`
 
Maple dsolve solution

Solving time : 0.002 (sec)
Leaf size : 35

dsolve(diff(x(t),t)*t+x(t)*g(t) = h(t),x(t),singsol=all)
 
\[ x = \left (\int \frac {h \left (t \right ) {\mathrm e}^{\int \frac {g \left (t \right )}{t}d t}}{t}d t +c_{1} \right ) {\mathrm e}^{-\int \frac {g \left (t \right )}{t}d t} \]
Mathematica DSolve solution

Solving time : 0.075 (sec)
Leaf size : 63

DSolve[{t*D[x[t],t]+x[t]*g[t]==h[t],{}},x[t],t,IncludeSingularSolutions->True]
 
\[ x(t)\to \exp \left (\int _1^t-\frac {g(K[1])}{K[1]}dK[1]\right ) \left (\int _1^t\frac {\exp \left (-\int _1^{K[2]}-\frac {g(K[1])}{K[1]}dK[1]\right ) h(K[2])}{K[2]}dK[2]+c_1\right ) \]
Sympy solution

Solving time : 39.604 (sec)
Leaf size : 49

Python version: 3.13.1 (main, Dec  4 2024, 18:05:56) [GCC 14.2.1 20240910] 
Sympy version 1.13.3
 
from sympy import * 
t = symbols("t") 
x = Function("x") 
ode = Eq(t*Derivative(x(t), t) + g(t)*x(t) - h(t),0) 
ics = {} 
dsolve(ode,func=x(t),ics=ics)
 
Eq((exp(Integral(g(t)/t, t)) - Integral(g(t)*exp(Integral(g(t)/t, 
t))/t, t))*x(t) + Integral((g(t)*x(t) - h(t))*exp(Integral(g(t)/t, 
t))/t, t), C1)
 
\[ \left (e^{\int \frac {g{\left (t \right )}}{t}\, dt} - \int \frac {g{\left (t \right )} e^{\int \frac {g{\left (t \right )}}{t}\, dt}}{t}\, dt\right ) x{\left (t \right )} + \int \frac {\left (g{\left (t \right )} x{\left (t \right )} - h{\left (t \right )}\right ) e^{\int \frac {g{\left (t \right )}}{t}\, dt}}{t}\, dt = C_{1} \]