# Using InterpolatingFunction in equations

I tried to use InterpolatingFunction in another ODE, but it doesn't work, because it seems for Mathematica that 2 functions are unknown instead of one.

 sol1 = NDSolve[{y'[x] == y[x], y == 2}, y[x], {x, 10, 15}]
sol2 = NDSolve[{f'[t] == With[{x = t}, Evaluate[sol1]], f == 2},
f[t], {t, 0, 10}]

During evaluation of In:= NDSolve::underdet: There are more dependent variables,
{f[t],y[t]}, than equations, so the system is underdetermined. >>


So, can I somehow use my function $y[x]$ in the next equation?.. The final goal is to solve Delay differential equation with time-dependent delay using method of steps manually.

• If you change the second line to sol2 = NDSolve[{f'[t] == (y[x] /. sol1[]) /. x -> t, f == 2}, f[t], {t, 0, 10}] you get a result (albeit with warning messages). Is it close to what you expect to get? – kglr Mar 10 '15 at 19:28
• do sol1 = y[x] /. First@NDSolve. You are then left with the problem that the range is {10,15} in the first equation and {0,10} in the second .. – george2079 Mar 10 '15 at 19:29
• @george2079 thanks, forgot replacing, such a stupid question... {10, 15} and {0, 10} is misprint, of course it should be {0, 15}. – newt Mar 10 '15 at 20:13

You need either to use the NDSolveValue:

sol1 = NDSolveValue[{y'[x] == y[x], y == 2}, y[x], {x, 0, 15}];
sol2 = NDSolveValue[{f'[t] == With[{x = t}, Evaluate[sol1]],
f == 2}, f[t], {t, 0, 10}];


Note that I also changed the ranges for the first solution.

Or (that's why you have an issue) you need to use ReplaceAll:

sol1 = NDSolve[{y'[x] == y[x], y == 2}, y[x], {x, 0, 15}];
sol2 = NDSolve[{f'[t] == First@With[{x = t}, Evaluate[y[x] /. sol1]],
f == 2}, f[t], {t, 0, 10}];

• Ok, I got it, but what's the meaning of replacing here? Am I right, that I need to use ReplaceAll because $y[x]$ is considered as defined function, whereas $sol1$ could be undefined? – newt Mar 10 '15 at 20:35
• No, because in Mathematica NDSolve, NSolve, Solve and other similar functions return the solutions in terms of replacement rules. So you need /. or introduced in Mathematica 10 *Value functions. – m0nhawk Mar 10 '15 at 20:40