1

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

Artes
  • 57,212
  • 12
  • 157
  • 245
Sosa
  • 303
  • 1
  • 6

1 Answers1

3

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.

  • Thank you so much, but what does /. mean? – Sosa Feb 22 '21 at 22:14
  • 1
    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 https://mathematica.stackexchange.com/questions/113306/what-is-the-meaning-of/113314 or you can just evaluate ?/. in a mathematica notebook to learn more –  Feb 23 '21 at 07:30
  • @Sosa, whenever you encounter a mysterious symbol in Mathematica code, highlight it in the notebook you are using, and press F1. – J. M.'s missing motivation Feb 25 '21 at 06:36