1
$\begingroup$

So I'm new to programming and I am trying to solve a very simple differential equation (i can do this by hand but the thing is i can't program it), the equation is a'[t] == - 0.0118, with the boundary conditions a[0]==3 and I want to know a[180]=?, how do I insert this (a[180]=?) into the code, this is my short code.

Sol = NDSolve[{a'[t] == -0.0118 , a[0] == 3 }, a, {t, 0, 180}]
Plot[Sol, {t, 0, 180}] 

It doesn't show anything in the plot

Thanks a lot, any type of help will be appreciated

$\endgroup$
3
$\begingroup$

You are practically there already. Observe that you are plotting the solution in the way you wrote the code. What you actually want to do, is to plot the function a[t] evaluated on the solution of the NDSolve

So, we have

Sol = NDSolve[{a'[t] == -0.0118, a[0] == 3}, a, {t, 0, 180}]
Plot[a[t] /. Sol, {t, 0, 180}]

This is the main thing that you want to notice: a[t] /. Sol

By that logic you can use

a[t] /. Sol /. t -> 180

to read the value at the point you want.

$\endgroup$
3
  • $\begingroup$ Thank you so much, but what does /. mean? $\endgroup$ – Sosa Feb 22 at 22:14
  • 1
    $\begingroup$ Hi, it is the way to tell mathematica to apply a rule or a list o rules on an expression. You can find more details here mathematica.stackexchange.com/questions/113306/… or you can just evaluate ?/. in a mathematica notebook to learn more $\endgroup$ – DiSp0sablE_H3r0 Feb 23 at 7:30
  • $\begingroup$ @Sosa, whenever you encounter a mysterious symbol in Mathematica code, highlight it in the notebook you are using, and press F1. $\endgroup$ – J. M.'s ennui Feb 25 at 6:36

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.