# Understanding solutions of differential equations

Solving $dx/dt$ = $-1/x$ gives the following solutions in Mathematica,

x(t) = $(x_0^2 -2t)^{1/2}$;

x(t) = -$(x_0^2 -2t)^{1/2}$

I'm able to analytically obtain the above solutions by solving the differential equation with x(0)= $x_0$.

Can we relate the above-mentioned solutions to the values of $x_0$?

For example, when $x_0$ > 0 which of the above solutions will hold and when $x_0$ < 0 which of the above solutions will be valid?

Any help would be much appreciated.

• Try with assumptions: {DSolve[{x'[t] == -1/x[t], x == x0}, x[t], t, Assumptions -> x0 > 0], DSolve[{x'[t] == -1/x[t], x == x0}, x[t], t, Assumptions -> x0 < 0], DSolve[{x'[t] == -1/x[t], x == x0}, x[t], t, Assumptions -> x0 == 0]} May 20, 2018 at 17:30
• Welcome to Mathematica StackExchange. In order to learn how to use this site take the tour. When copying equations from a notebook to your question one should format using inline code by selecting the code and clicking the {} button above the edit window. It is recommended that you browse the Markdown help May 20, 2018 at 21:23
• @MariuszIwaniuk - more succinctly: DSolve[{x'[t] == -1/x[t], x == x0}, x[t], t, Assumptions -> #] & /@ {x0 > 0, x0 < 0, x0 == 0} May 21, 2018 at 1:44

Let's study the solution to your differential equation (second line below).

sol = DSolve[{x'[t] == -1/x[t], x == x0}, x[t], t]

(* {{x[t] -> -Sqrt[-2 t + x0^2]}, {x[t] -> Sqrt[-2 t + x0^2]}} *)


We will make two functions for each of the two possible solutions. One could cut and paste the solutions, however another way is to Evaluate the part of sol corresponding to each solution.

x1[t_, x0_] := Evaluate[sol[[1, 1, 2]]]

x2[t_, x0_] := Evaluate[sol[[2, 1, 2]]]


The Evaluate is required to properly define the functions x1 and x2. Be sure to check that

?x1


produces It should be clear that we don't care whether x0 is a positive or negative Real number as the square of the negative number will result in a positive value.

Let's plot the two solutions for the cases x0 = 1 and x0 = 0.

With[
{
x0 = 1
},
Plot[{x1[t, x0], x2[t, x0]}, {t, -2, 2}, PlotStyle -> {Black, Red}]
] With[
{
x0 = 0
},
Plot[{x1[t, x0], x2[t, x0]}, {t, -2, 2}, PlotStyle -> {Black, Red}]
] From these plots I hope it is clear that both solutions are applicable. The plot only shows results for values where the function has a Real result. That condition will be met provided: If one is interested in Complex results, the restriction is removed and you might use Table to get a list of the results.

TableForm[
With[
{
x0 = 1
},
Table[{t, x1[t, x0], x2[t, x0]}, {t, -2, 2}]
],
TableHeadings -> {None, {"t", "x1[t]", "x2[t]"}}
] 