# About a simple differential equation

Just a simple differential equation.Even we can hand to solve it.But the Mathematica give a error.

DSolve[{2*y[x]*y''[x] == y'[x]^2 + y[x]^2, y[0] == 1, y'[0] == -1},
y[x], x]


DSolve::bvnul: For some branches of the general solution, the given boundary conditions lead to an empty solution. {}

ps:The answer is y=e^(-x).

• Are you sure of your result? it seems to me that $y=e^x$ is incompatible with $y'(0)=-1$. More generally, what is your question here? – MarcoB Dec 8 '15 at 6:17
• @MarcoB Thanks for your promption,and I have updated the result.My question is how to use Mathematica to solve the differential equation in a right way to get the result? – yode Dec 8 '15 at 6:31
• @MarcoB the solution $y=e^x$ seems to be correct. Maple gives that answer: !Mathematica graphics – Nasser Dec 8 '15 at 8:16
• The solution $y=e^x$ does satisfy the ode and the initial conditions. – Nasser Dec 8 '15 at 8:36
• @Nasser No!The e^x cannot satifay the y'(0)=-1 – yode Dec 8 '15 at 8:50

As pointed out in the other answer/comment by @Lotus, Mathematica can solve the equation in general:

DSolve[{2*y[x]*y''[x] == y'[x]^2 + y[x]^2}, y, x]

(* {{y[x] -> E^-x (E^x + E^(2 C[1]))^2 C[2]}} *)


In particular, if we use the more general initial conditions y[0] == y0 and y'[0] == yp0, then Mathematica can apply these initial conditions with no problem:

soln = DSolve[{2*y[x]*y''[x] == y'[x]^2 + y[x]^2, y[0] == y0, y'[0] == yp0}, y[x], x]

(* {{y[x] -> (E^-x (y0 + E^x y0 - yp0 + E^x yp0)^2)/(4 y0)}} *)


And if you then specify y0 -> 1 and yp0 -> -1, then Mathematica gets the correct result:

(y[x] /. soln[[1, 1]]) /. {y0 -> 1, yp0 -> -1}

(* E^-x *)


Why Mathematica is unable to find this solution without our intervention is a bit mysterious to me. Most likely, DSolve is finding the general solution (with the $C_i$ coefficients) and then noting that there isn't a real-valued solution for the $C_i$'s that yields the desired initial conditions. (The solution $e^{-x}$ is a limit of Mathematica's general solution: $C_1 \to \infty$ and $C_2 \to 0$ in such a way that $e^{4 C_1} C_2 = 1$.) However, if we asking for the solution to be expressed in terms of $y(0)$ and $y'(0)$, the result is (presumably) auto-simplified to the extent that the solution can be found for all $y(0)$ and $y'(0)$. (Except for $y(0) = 0$ and $y'(0) \neq 0$, for which there is no solution.)

This is a Comment and not an answer.

The problem here is that there is no "general solution" for the differential equation. Here is what happens without initial conditions:

In[31]:= gensol = DSolve[{2*y[x]*y''[x] == y'[x]^2 + y[x]^2}, y, x]

Out[31]= {{y -> Function[{x}, E^-x (E^x + E^(2 C[1]))^2 C[2]]}}


The above solution is correct, as can be verified easily:

In[41]:= {2*y[x]*y''[x] == y'[x]^2 + y[x]^2} /. gensol // Simplify

Out[41]= {{True}}


DSolve uses Solve internally to solve for the constants and here is what happens there:

In[38]:= Solve[{y[0] == 1, y'[0] == -1} /. gensol[[1, 1]], {C[1],
C[2]}]

Out[38]= {}


With NDSolve though, it just takes a particular branch based on the range of x specified.

I guess we have to start with the general solution and find constants suitably.

By the way Does Maple solve this ?

• No,The differential equation have a solution,the e^(-x) satisfy every condition and the initial equation. – yode Dec 8 '15 at 11:20
• The "general solution" found by Mathematica has $e^{-x}$ as a limit: $C_1 \to \infty$ and $C_2 \to 0$ in such a way that $e^{4 C_1} C_2 = 1$. – Michael Seifert Dec 8 '15 at 19:53

With a bit of assistance,DSolve can obtain a simpler general answer. Begin by changing dependent variables.

eq = 2*y[x]*y''[x] - y'[x]^2 - y[x]^2
eq2 = eq /. y'[x] -> p[y] /. y''[x] -> p[y]*p'[y] /. y[x] -> y
sol = DSolve[eq2 == 0, p[y], y]
(*{{p[y] -> -Sqrt[y] Sqrt[y + C[1]]}, {p[y] -> Sqrt[y] Sqrt[y + C[1]]}}*)


Boundary conditions are: y[0] == 1, y'[0] == -1. Now we find C[1] constant:

sol1 = Solve[-1 == (p[y] /. sol[[1]]) /. y -> 1, C[1]]
(*{{C[1] -> 0}}*)
sol2 = Solve[-1 == (p[y] /. sol[[2]]) /. y -> 1, C[1]]
(*{no solutions}*)


General Solution of this equation is:

 SolE = First@DSolve[y'[x] - ((p[y] /. sol[[1]]) /. y -> y[x]) == 0, y[x], x]
(*{y[x] -> 1/4 E^(-x - C[2]) (E^C[2] - E^x C[1])^2}*)


$$\left\{y(x)\to \frac{1}{4} e^{-c_2-x} \left(e^{c_2}-c_1 e^x\right){}^2\right\}$$

The above solution is correct, as can be verified easily:

Z = (y[x] /. SolE)
FullSimplify[2*Z*D[Z, x, x] - D[Z, x]^2 - Z^2 == 0]
(*True*)


Now we find C[2] constant:

 sol4 = First@Solve[1 == (y[x] /. SolE /. C[1] -> 0) /. x -> 0, C[2], Reals]
(*{C[2] -> 2 Log[2]}*)


Special solution of this equation is:

 Y[x] == (y[x] /. SolE) /. C[1] -> 0 /. C[2] -> C[2] /. sol4
(*Y[x] == E^(-x)*)


$$y(x)=e^{-x}$$

• @Can you know the function is e^(-x) by your InterpolatingFunction If I don't tell you the result? – yode Dec 8 '15 at 11:18
• @yode See this: mathematica.stackexchange.com/questions/19042/… – Mariusz Iwaniuk Dec 8 '15 at 13:01
• @Thanks your link.But you don't know the result is e^x – yode Dec 8 '15 at 14:31
• @yode. I am sure that e^(-x) is correct answer. – Mariusz Iwaniuk Dec 8 '15 at 15:15
• Sorry for my typo,"Thanks your link.But you don't know the result is e^(-x) by your InterpolatingFunction still." – yode Dec 8 '15 at 15:19