# Solve the differential equation cos(x)dy/dx+y=sin(x) given that Y=2 when X=0 ?

Jun 26, 2018

$y = 1 - \frac{\left(x - 1\right) \cos x}{1 + \sin x}$

#### Explanation:

For $x \ne \frac{\pi}{2} + k \pi$ divide by $\cos x$:

$\frac{\mathrm{dy}}{\mathrm{dx}} + y \sec x = \tan x$

Solve first the homogeneous equation:

$\frac{\mathrm{dy}}{\mathrm{dx}} + y \sec x = 0$

which is separable:

$\frac{\mathrm{dy}}{\mathrm{dx}} = - y \sec x$

$\frac{\mathrm{dy}}{y} = - \sec x \mathrm{dx}$

$\int \frac{\mathrm{dy}}{y} = - \int \sec x \mathrm{dx}$

$\ln \left\mid y \right\mid = - \ln \left\mid \sec x + \tan x \right\mid + C$

$y = \frac{c}{\sec x + \tan x}$

Using the method of variable coefficient look now for a particular solution of the complete equation in the form:

$\overline{y} = \frac{c \left(x\right)}{\sec x + \tan x}$

$\frac{\mathrm{db} a r y}{\mathrm{dx}} = \frac{c ' \left(x\right) \left(\sec x + \tan x\right) - c \left(x\right) \left(\sec x \tan x + {\sec}^{2} x\right)}{\sec x + \tan x} ^ 2$

$\frac{\mathrm{db} a r y}{\mathrm{dx}} = \frac{c ' \left(x\right) \left(\sec x + \tan x\right) - \sec x c \left(x\right) \left(\sec x + \tan x\right)}{\sec x + \tan x} ^ 2$

$\frac{\mathrm{db} a r y}{\mathrm{dx}} = \frac{c ' \left(x\right) - \sec x c \left(x\right)}{\sec x + \tan x}$

Substitute in the complete equation:

$\frac{\mathrm{db} a r y}{\mathrm{dx}} + y \sec x = \tan x$

$\frac{c ' \left(x\right) - \sec x c \left(x\right)}{\sec x + \tan x} + \frac{c \left(x\right) \sec x}{\sec x + \tan x} = \tan x$

$\frac{c ' \left(x\right)}{\sec x + \tan x} = \tan x$

$c ' \left(x\right) = \sec x \tan x + {\tan}^{2} x$

Using the trigonometric identity: ${\tan}^{2} x = {\sec}^{2} x - 1$

$c ' \left(x\right) = \sec x \tan x + {\sec}^{2} x - 1$

$c \left(x\right) = \int \left(\sec x \tan x + {\sec}^{2} x - 1\right) \mathrm{dx}$

$c \left(x\right) = \sec x + \tan x - x + {c}_{1}$

Choose the solution for ${c}_{1} = 0$:

$\overline{y} = \frac{\sec x + \tan x - x}{\sec x + \tan x} = 1 - \frac{x}{\sec x + \tan x}$

The complete solution is then:

$y = \frac{c}{\sec x + \tan x} - \frac{x}{\sec x + \tan x} + 1$

$y = 1 - \frac{x - c}{\sec x + \tan x}$

In fact:

$\frac{\mathrm{dy}}{\mathrm{dx}} = \frac{\left(x - c\right) \sec x - 1}{\sec x + \tan x}$

$\cos x \frac{\mathrm{dy}}{\mathrm{dx}} + y = \frac{\left(x - c\right) - \cos x}{\sec x + \tan x} + 1 - \frac{x - c}{\sec x + \tan x} =$

$\therefore = 1 - \cos \frac{x}{\sec x + \tan x}$

$\therefore = \frac{\sec x + \tan x - \cos x}{\sec x + \tan x}$

$\therefore = \frac{1 + \sin x - {\cos}^{2} x}{1 + \sin x}$

$\therefore = \frac{{\sin}^{2} x + \sin x}{1 + \sin x} = \sin x$

Note that we can write the general solution also as:

$y = 1 - \frac{\left(x - c\right) \cos x}{1 + \sin x}$

If we let $x = 0$ then:

$y \left(0\right) = 1 + c$

so that from the initial condition:

$y \left(0\right) = 2$ we get $c = 1$.

$y = 1 - \frac{\left(x - 1\right) \cos x}{1 + \sin x}$