-1
$\begingroup$

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[0] == 2}, y[x], {x, 10, 15}]
   sol2 = NDSolve[{f'[t] == With[{x = t}, Evaluate[sol1]], f[0] == 2}, 
  f[t], {t, 0, 10}]

 During evaluation of In[89]:= 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.

$\endgroup$
  • 1
    $\begingroup$ If you change the second line to sol2 = NDSolve[{f'[t] == (y[x] /. sol1[[1]]) /. x -> t, f[0] == 2}, f[t], {t, 0, 10}] you get a result (albeit with warning messages). Is it close to what you expect to get? $\endgroup$ – kglr Mar 10 '15 at 19:28
  • $\begingroup$ 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 .. $\endgroup$ – george2079 Mar 10 '15 at 19:29
  • $\begingroup$ @george2079 thanks, forgot replacing, such a stupid question... {10, 15} and {0, 10} is misprint, of course it should be {0, 15}. $\endgroup$ – newt Mar 10 '15 at 20:13
1
$\begingroup$

You need either to use the NDSolveValue:

sol1 = NDSolveValue[{y'[x] == y[x], y[0] == 2}, y[x], {x, 0, 15}];
sol2 = NDSolveValue[{f'[t] == With[{x = t}, Evaluate[sol1]], 
    f[0] == 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[0] == 2}, y[x], {x, 0, 15}];
sol2 = NDSolve[{f'[t] == First@With[{x = t}, Evaluate[y[x] /. sol1]], 
    f[0] == 2}, f[t], {t, 0, 10}];
$\endgroup$
  • $\begingroup$ 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? $\endgroup$ – newt Mar 10 '15 at 20:35
  • $\begingroup$ 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. $\endgroup$ – m0nhawk Mar 10 '15 at 20:40

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.