Quite often a differential equation may be viewed as an algebraic problem. In such a view, the integration constant C[1]
might naturally be viewed as an element of the projective line. But in the natural Mathematica point of view, the constant is taken to belong to an affine subspace, namely the real number line. One could approach finding a solution by taking C[1]
to belong to the projective space, via C[1] -> a/b
, or by taking it to belong to a different affine subspace, say via C[1] -> 1/C[1]
.
In both approaches below, we solve the general differential equation, remap C[1]
, and solve the boundary condition for C[1]
.
Here is an approach via the projective line, replacing C[1]
by the ratio a/b
. A potential pitfall here is that a
and b
are defined only up to a constant of proportionality, but it turns out Solve
can handle it in this case.
ysol = First @ DSolve[{y'[x] + 2 E^x y[x] - y[x]^2 == E^(2 x) + E^x}, y[x], x] /.
C[1] -> a/b // Simplify
Solve[D[y[x] /. ysol, x] == 1 /. x -> 0, {a, b}]
ysol /. First[%]
(*
{y[x] -> E^x + b/(a - b x)}
Solve::svars: Equations may not give solutions for all "solve" variables. >>
{{b -> 0}}
{y[x] -> E^x}
*)
A better way perhaps is to take a different affine subspace by moving some finite point to infinity. The replacement C[1] -> 1/C[1]
moves 0
to infinity (so we lose the solution where the original C[1] == 0
). In this formulation there is just one constant to solve for, and at least in this case Solve
gets the multiplicity right.
ysol = First @ DSolve[{y'[x] + 2 E^x y[x] - y[x]^2 == E^(2 x) + E^x}, y[x], x] /.
C[1] -> 1/C[1] // Together
Solve[D[y[x] /. ysol, x] == 1 /. x -> 0, C[1]]
ysol /. First[%]
(*
{y[x] -> (-E^x - C[1] + E^x x C[1])/(-1 + x C[1])}
{{C[1] -> 0}, {C[1] -> 0}}
{y[x] -> E^x}
*)
Update -- General solution comprising all solutions
If we take an even less familiar route and move a non-real, complex number, such as I
, to infinity, we can get the solution(s) for all valid initial (real) values for y'[x]
, which must be at least 1
.
ysol = First@ DSolve[{y'[x] + 2 E^x y[x] - y[x]^2 == E^(2 x) + E^x}, y[x], x] /.
C[1] -> 1/(C[1] - I) // Together;
Csol = Solve[D[y[x] /. ysol, x] == c /. x -> 0, C[1]];
gensol = {y -> Function @@ #} & /@ Thread[{x, y[x] /. ysol /. Csol // Simplify}]
{y[0], y'[0]} /. gensol // Simplify (* initial values *)
y[x] /. gensol /. c -> 1 (* OP's desired solution *)
(*
{{y -> Function[x, (-Sqrt[-1 + c] + E^x (1 + Sqrt[-1 + c] x))/(1 + Sqrt[-1 + c] x)]},
{y -> Function[x, (Sqrt[-1 + c] + E^x - Sqrt[-1 + c] E^x x)/(1 - Sqrt[-1 + c] x)]}}
{{1 - Sqrt[-1 + c], c}, {1 + Sqrt[-1 + c], c}} (* initial values *)
{E^x, E^x} (* OP's desired solution *)
*)
Generically, there are two distinct solutions for each initial value for y'[0]
, but they coincide for y'[0] == 1
.
dsolve({diff(y(x), x)+2*y(x)*exp(x)-y(x)^2 = exp(2*x)+exp(x), (D(y))(0) = 1}, y(x))
performsy(x) = exp(x)
. $\endgroup$