Message Boards Message Boards

Unable to plot solution derivative after NDsolve?

Posted 1 year ago

Hello, Here is my Mathematica code :

eqn1 = a'[t] == b[t]
 K = 0.0003
 eqn2 = b'[t] == 
  a[t]/(a[t]^2 + 1/a[t]^2) (2 b[t]^2/a[t]^4 + K r[t] a[t]^4 - 
     K/(r[t] a[t]^4))
 eqn3 = 
 r'[t] == 
  b[t] r[t]/
    a[t] ((b'[t]/a[t] (a[t]^2 - 1/a[t]^2) + 
        2 b[t]^2/a[t]^4)/(K (a[t]^4 r[t] + 1/(a[t]^4 r[t]))) - 4)
 s = 
 NDSolve[{eqn1, eqn2, eqn3, a[0] == r[0] == 1, b[0] == 400}, {a[t], 
   b[t], r[t]}, {t, 0, 3}, Method -> "BDF"]


Plot[Evaluate[r[t] /. s], {t, 0, 0.01}, 
 PlotRange -> {{0, 0.005}, All}]

Plot[Evaluate[b[t] /. s], {t, 0, 0.05}, 
 PlotRange -> {{0, 0.02}, All}]

Plot[Evaluate[b'[t] /. s], {t, 0, 0.02}, 
 PlotRange -> {{0, 0.02}, All}]

r(t), a(t) and b(t) plot successfully but not b'(t) (nor a'(t) nor r'(t)) : I just get an empty graph without any error message! I have very little experience in Mathematica. Thanks in advance for any helpful advice and comments.

Try either

NDSolve[..., {a, b, r}]

without the arguments [t] or

Plot[Evaluate[D[b[t] /. s, t]], ...]

In your code, s replaces b[t] but not b'[t], so either change the NDSolve call to return a function for b instead of an expression for b[t], or change your usage of s to process (b[t] /. s). An alternative is to use NDSolveValue.

I think it would be helpful if this were explained in the N/DSolve documentation pages.

POSTED BY: Michael Rogers
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract