0

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?

Liuba Orlova
  • 101
  • 5
  • Your example is continuous at $t=1$, so why should joining them produce a discontinuity? Also, which given solution did you use? – Carl Woll Feb 15 '18 at 22:33
  • 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? – halirutan Feb 16 '18 at 01:29

1 Answers1

1

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

halirutan
  • 112,764
  • 7
  • 263
  • 474