0
$\begingroup$

If I have, for example

sol1 = NDSolve[{u'[t] == u[t], u[0] == 1}, u, {t, 0, 1}]
sol2 = NDSolve[{u'[t] == u[t], u[0] == 1}, u, {t, 1, 2}]
sol = Join[sol1, sol2]

I expected to get one function that goes from 0 to 2, but intead I get a list of two functions. How can I join sol1 and sol2 in order to get one function on a larger interval?

$\endgroup$
  • $\begingroup$ Your example is continuous at $t=1$, so why should joining them produce a discontinuity? Also, which given solution did you use? $\endgroup$ – Carl Woll Feb 15 '18 at 22:33
  • $\begingroup$ I already wrote this today: Just because you wish something works like you want it to, doesn't make it true. Have you ever considered reading the definition of Join? $\endgroup$ – halirutan Feb 16 '18 at 1:29
0
$\begingroup$

How bout this

sol1 = NDSolveValue[{u'[t] == u[t], u[0] == 1}, u, {t, 0, 1}]
sol2 = NDSolveValue[{u'[t] == u[t], u[0] == 1}, u, {t, 1, 2}]

sol[t_?NumericQ] :=  Piecewise[{{sol1[t], 0 <= t <= 1}, {sol2[t], 1 < t <= 2}}];

Plot[sol[t], {t, 0, 2}]

Mathematica graphics

$\endgroup$

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