Let's study the solution to your differential equation (second line below).
sol = DSolve[{x'[t] == -1/x[t], x[0] == 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]"}}
]
{DSolve[{x'[t] == -1/x[t], x[0] == x0}, x[t], t, Assumptions -> x0 > 0], DSolve[{x'[t] == -1/x[t], x[0] == x0}, x[t], t, Assumptions -> x0 < 0], DSolve[{x'[t] == -1/x[t], x[0] == x0}, x[t], t, Assumptions -> x0 == 0]}
$\endgroup${}
button above the edit window. It is recommended that you browse the Markdown help $\endgroup$DSolve[{x'[t] == -1/x[t], x[0] == x0}, x[t], t, Assumptions -> #] & /@ {x0 > 0, x0 < 0, x0 == 0}
$\endgroup$