One way, if you don't mind the IDA method of numerical integration:
NDSolve[{z'[t]^2 == z[t], z[0] == 1, z'[0] == 1}, {z}, {t, 0, 10},
Method -> {"EquationSimplification" -> "Residual"}]
Another way (see this tutorial):
states =
NDSolve`ProcessEquations[{z'[t]^2 == z[t], z[0] == 1}, {z}, {t, 0,
10}];
There are two states, one for each solution:
NDSolve`ProcessSolutions[states[[1]], "Forward"]
{z[0.] -> 1., Derivative[1][z][0.] -> -1.}
NDSolve`ProcessSolutions[states[[2]], "Forward"]
{z[0.] -> 1., Derivative[1][z][0.] -> 1.}
Pick the desired one:
{state} =
Pick[states,
Positive[
z'[0.] /. NDSolve`ProcessSolutions[#, "Forward"] & /@ states]];
Integrate and retrieve the solution:
NDSolve`Iterate[state,
NDSolve`SolutionDataComponent[state@"VariableRanges", "Time"]]
sol = NDSolve`ProcessSolutions[state]
{z -> InterpolatingFunction[{{0., 10.}}, ...]
Third way, using an internal hack:
Internal`InheritedBlock[{Solve},
Unprotect@Solve;
Solve[eq_, v_, opts___] /; ! TrueQ[$in] := Block[{$in = True},
Solve[eq, v,
Assumptions -> v ∈ PositiveReals && z ∈ Reals,
opts]];
Protect@Solve;
NDSolve[{z'[t]^2 == z[t], z[0] == 1}, {z}, {t, 0, 10}]
]
The trouble with using Assuming[...]
etc. without the hack is that z'[t]
is rewritten as a Module
variable with an unpredictable module number appended to it (for example, z$64135
).
z'[t]==Sqrt[z[t]]
. Can you rearrange your example in a similar way? $\endgroup$Select[sol, And @@ (Positive[z[#]] & /@ {0, 5, 10}) /. # &]
$\endgroup$