For #x != pi/2 + kpi# divide by #cosx#:
#dy/dx +y secx = tanx#
Solve first the homogeneous equation:
#dy/dx + ysecx= 0#
which is separable:
#dy/dx = -ysecx#
#dy/y = - secxdx#
#int dy/y = -int secxdx#
#lnabs y = -ln abs(secx+tanx) +C#
#y = c/(secx+tanx)#
Using the method of variable coefficient look now for a particular solution of the complete equation in the form:
#bar y = (c(x))/ (secx+tanx)#
#(dbary)/dx = (c'(x) (secx+tanx) -c(x)(secxtanx +sec^2x))/(secx+tanx)^2#
#(dbary)/dx = (c'(x) (secx+tanx) -secx c(x)(secx +tanx))/(secx+tanx)^2#
#(dbary)/dx = (c'(x) -secx c(x))/(secx+tanx)#
Substitute in the complete equation:
#(dbary)/dx +ysecx = tanx#
#(c'(x) -secx c(x))/(secx+tanx)+(c(x) secx)/(secx+tanx) = tanx#
#(c'(x))/(secx+tanx)= tanx#
#c'(x)= secxtanx+tan^2x#
Using the trigonometric identity: #tan^2x = sec^2x-1#
#c'(x)= secxtanx+sec^2x-1#
#c(x) = int (secxtanx+sec^2x-1)dx#
#c(x) = secx+tanx -x +c_1#
Choose the solution for #c_1 =0#:
#bary = (secx+tanx -x)/(secx+tanx) = 1-x/(secx+tanx)#
The complete solution is then:
#y = c/(secx+tanx) -x/(secx+tanx) +1#
#y= 1-(x-c)/(secx+tanx)#
In fact:
#dy/dx = ((x-c)secx-1)/(secx+tanx)#
#cosx dy/dx +y =((x-c)-cosx)/(secx+tanx)+1-(x-c)/(secx+tanx) = #
#:. = 1- cosx/(secx+tanx)#
#:. = (secx+tanx- cosx)/(secx+tanx)#
#:. = (1+sinx- cos^2x)/(1+sinx)#
#:. = (sin^2x+sinx)/(1+sinx) = sinx#
Note that we can write the general solution also as:
#y= 1-((x-c)cosx)/(1+sinx)#
If we let #x=0# then:
#y(0) = 1+c#
so that from the initial condition:
#y(0) = 2# we get #c=1#.
#y= 1-((x-1)cosx)/(1+sinx)#