As my differential function is relatively complex I do not want to do the detour of finding an explicit solution via DSolve for it but rather use an FindRoot-like approach by guessing initial starting values.

Following example:

Let z[t] be the differential where the start and end values are known:

z[0]=z0 and z[tmax]=zend, but the end time tmax is unknown.

The (simplified) differential (where the paths of l2[t]and l3[t] as well as their end values l2final and l3final are well-defined) is:

DSolve[{z[0] == z0, z[tmax] == zend, z'[t]==f[l20[t],l3[t]],l2[tmax]==l2final, l30[tmax]==l3final}, z[t],t]

The only unkown is tmax. So I don't want to do the DSolve described as I don't care about an explicit solution of z[t]. But I rather want to search for something like:


Does anybody have an idea how to combine both approaches EFFICIENTLY?

Btw: z[t] is continously increasing as well as l2[t] and l3[t]


It helps to give code that can reproduce you're problem, but here's a guess at what you're after. I removed the conditions l2[tmax]==l2final, l30[tmax]==l3final because if l2 and l3 are well defined and tmax is defined by z[tmax] == tend, then l2final and l3final are determined by the result.

WhenEvent is the way to solve z[t] == zend.

f[x_, y_] := x + y^2/4;
l20[t_] := t + Cos[4 t]^2; l3[t_] := 2 t + Sin[2 t];
z0 = 10.;
zend = 100.;
sol = First @ NDSolve[{z[0] == z0, z'[t] == f[l20[t], l3[t]]
                    WhenEvent[z[t] == zend, tmax = t; "StopIntegration"]}, 
        z[t], {t, 0, Infinity}]



Plot[sol[t], Evaluate[{t, Sequence @@ First@sol["Domain"]}]]

Mathematica graphics


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.