I am trying to compare an approximation formula for a particular nonlinear ODE with different right hand sides. The code I use is:

sol = NDSolve[{w''[t] + Exp[w[t]] == Sin[t], w[0] == 0, 
w'[0] == 0}, w, {t, 0, 10}, Method->"StifnessSwitching"];
wsol[t_] := Evaluate[w[t] /. sol]
wBlue[s_, t_] := 
 1/s NIntegrate[
   Log[1 - Tanh[(t - t1)/Sqrt[2]]^2] Sin[t1], {t1, 0, t}]

However, NDSolve gives

NDSolve::ndnum: Encountered non-numerical value for a derivative at t == 0.`.

I guess it is because of the right hand side f[t]. Is there any way to get rid of this and plot wsol and wBlue against t?

Thank you for your time.

  • 2
    $\begingroup$ You miss typed "StiffnessSwitching" - but you do not need that in the first place. $\endgroup$
    – user21
    Feb 1, 2018 at 11:08
  • 1
    $\begingroup$ Thanks! There was a minor typo, that's all. $\endgroup$ Feb 1, 2018 at 11:21

1 Answer 1


You have to correct the definition f[t]:

f[t_] := Sin[t]

sol = NDSolve[{w''[t] + Exp[w[t]] == f[t], w[0] == 0, w'[0] == 0},w, {t, 0,10}]
(* {{w -> InterpolatingFunction[{{0., 10.}}, <>]}} *)
  • $\begingroup$ It was a typo in the code. The NDSolve still gives the same error. I tried several built in methods like BDF, MethodOfLines, ExplicitRungeKutta, etc. $\endgroup$ Feb 1, 2018 at 10:32
  • $\begingroup$ Before(!) you execute NDSolve f[t] must be defined. Otherwise NDSolve gives the error NDSolve::ndnum: $\endgroup$ Feb 1, 2018 at 10:38
  • $\begingroup$ Dear Ulrich, I have already fixed that issue. $\endgroup$ Feb 1, 2018 at 10:41
  • $\begingroup$ f[t_] := Sin[t] should be the first line in your code. If so your code run's without error warning! $\endgroup$ Feb 1, 2018 at 10:45
  • $\begingroup$ Can you run it successfully on your machine? I get the same error even when I write Sin[t] directly in the NDSolve. $\endgroup$ Feb 1, 2018 at 10:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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