Solving first order differential equation numerically

176 Views Asked by At

The problem is of the following form: $\frac{dr}{dt}$ = $f(r)$, so $\frac{1}{f(r)} dr = dt$. My goal is to get some $r(t)$ from this differential equation by numerically integrating this, that is, a value for $r$ at every $t$. The conditions are $r(0) = r_0$ and $r(\infty) = \infty$. The problem I run into is that I am not quite sure what the limits would be to get such values for $r(t)$. Any suggestions on where to go from this would be greatly appreciated, thanks.

3

There are 3 best solutions below

0
On BEST ANSWER

First of all, this is a first order problem, you do not get to fix two conditions, only one. Once you choose $r(0)=r_0$, the solution is determined for all $t$ and it may or may not satisfy $r(\infty)=\infty$. The simplest method you can use is Euler's method: you choose equally spaced points $t_0,t_1=t_0+h, t_2=t_0+2h, \cdots$, and build the sequence $$ \begin{cases} R_0 = r(t_0)=r_0\\ R_{n+1}=R_n + h f(R_n) \end{cases} $$

Naturally, $R_i$ will be the approximate value of $r(t_i)$. You may have to use very small $h$ for precise results but it has the advantage of being very easy to implement. If you want more accurate methods, you may want to lookup Runge-Kutta methods.

In terms of the integral form of the equation this corresponds to say that

$$ r(t+h)= r(t) + \int_t^{t+h} f(r(s)) \,ds \approx r(t) + h f(r(t)).$$

2
On

$\int_{r_0}^{a} \frac{1}{f(r)}dr = t$, with $a = r(t)$.

Now let $F(r)$ be the antiderivative of the integrand.

$F(r(t)) - F(r(0)) = t$. Now if we know how to invert $F(r)$, we can find our $r(t)$.

7
On

Write it as, $r_{t_1}=r_{t_0}+\int_{t_0}^{t_1}f(t)dt$, where $0=t_0\leq t_1\leq\cdots$. Apply your favorite quadrature rule, for instance, $r_{t_1}=0+(t_1-0)\frac{f(t_1)+f(0)}{2}$. This way use it to get $r(t_2)$ and so on.