I am solving a nonlinear ODE using NDSolve
, and one of the terms is an implicit nonlinear function of the dependent variable, for which I am using FindRoot
. Here's a trivial example:
y[x_] := y /. FindRoot[Exp[Log[y]] == x, {y, 1}];
I can plot this function, and it gives a straight line y= x
, but when I put the function into NDSolve, I get an error message.
s = NDSolve[{h'[t] == -y[h[t]], h[0] == 1}, h, {t, 0, 2}]
and then
Plot[Evaluate[h[t]/.s],{t,0,2}]
If the function y[h[t]]
were working, the solution would be h[t]=Exp[-t]
. Does every term in NDSolve
have to be an explicit function? Is there a way around this?
y[x_?NumericQ] := ...
$\endgroup$NDSolve[{Exp[Log[-h'[t]]] == h[t], h[0]==1}, h, {t, 0, 2}]
instead? $\endgroup$