0
$\begingroup$

I been trying to plot the derivative function of j[t], being j'[t]. Here a look to the code.Screenshot from the code I would appreciate your help. Thank you

g = 9.81; ve = 20.47; mr = 0.3; mw = 0.75; b = 0.0024052;
J = NDSolve[{j'[
     t] == -(g - (mw*ve^2*Exp[-ve*t])/(mr + 
        mw*Exp[-ve*t])) + (mw*ve*Exp[-ve*t])/(mr + mw*Exp[-ve*t])*
      j[t] - (b/(mr + mw*Exp[-ve*t]))*j[t]^2, j[0] == 0}, j[t], {t, 0, 
5}] 

Plot[j[t]/.J , {t, 0,10}, PlotRange -> {-60,60}]

Plot[Evaluate[j'[t]/.J], {t, 0,10}, PlotRange -> {-100,100}]
$\endgroup$
  • 1
    $\begingroup$ dj=D[j[t]/.J,t]; Plot[dj,{t,0,10},PlotRange->All] seems to work just fine with no other changes $\endgroup$ – Bill Aug 12 at 21:00
  • $\begingroup$ Great, it seems to work fine, however and as other question, how do you do it in order to get the integrated function of j[t]? @Bill $\endgroup$ – Luis Aug 12 at 22:11
  • $\begingroup$ s=Integrate[(j[t]/.J)[[1]],{t,0,x}]; Plot[s,{x,0,8}] seems to work just fine. Test all this very carefully to make certain that it is correct. $\endgroup$ – Bill Aug 13 at 1:38
  • $\begingroup$ You can integrate an InterpolatingFunction directly: Integrate[j[t] /. First[J], t] $\endgroup$ – Michael E2 Aug 13 at 14:11
1
$\begingroup$

Try NDSolveValue

J = NDSolveValue[{j'[t] == -(g - (mw*ve^2*Exp[-ve*t])/(mr +mw*Exp[-ve*t])) + (mw*ve*Exp[-ve*t])/(mr + mw*Exp[-ve*t])*j[t] - (b/(mr + mw*Exp[-ve*t]))*j[t]^2, j[0] == 0}, j, {t,0,5}] 

Plot[ J'[t] , {t, 0,10}, PlotRange -> {-100,100}]
$\endgroup$
1
$\begingroup$

Request the function j, not the expression j[t], from NDSolve:

g = 9.81; ve = 20.47; mr = 0.3; mw = 0.75; b = 0.0024052;
J = NDSolve[{j'[t] == -(g - (mw*ve^2*Exp[-ve*t])/(mr + 
        mw*Exp[-ve*t])) + (mw*ve*Exp[-ve*t])/(mr + mw*Exp[-ve*t])*
      j[t] - (b/(mr + mw*Exp[-ve*t]))*j[t]^2, j[0] == 0},
  j, {t, 0, 5}] 

Then J will have the form of (a nested list containing) a substitution rule {{j -> ...}} and it will replace j in j'[t] by the interpolating function solution NDSolve computed; this function will be automatically differentiated. The following then will work:

Plot[Evaluate[j'[t] /. J], {t, 0, 10}, PlotRange -> {-100, 100}]

Some find getting the function directly from NDSolveValue convenient (see @Ulrich's answer), which I do at times. If I need to plug j into various expressions, the substitution rule is very convenient. On the other hand, a substitution rule of the form j[t] -> ... is less convenient because it cannot be used to replace j'[t] with the solution. I never use that form.

$\endgroup$

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.