Problem:
Walk through one time-step of 4th-order Runge-Kutta with simple differential equation system $y'=y$, $y(0)=1$ and $\Delta t=2$.
Identify the correct values for f1; f2; f3; f4 and y(2).
Solution:
It is always good to know the solution to the differential equation first, in this case it is really easy.
$ \begin{eqnarray*} \frac{dy}{dt} &=& y \\ \frac{1}{y}\frac{dy}{dt} &=& 1 \\ \int{\frac{1}{y}\frac{dy}{dt}dt} &=& \int{1dt} \\ \log y &=& t + C_1 \\ y &=& e^{t + C_1} \\ &=& C_2e^t \\ \end{eqnarray*} $
Now the initial condition decides $ C_2 = 1 $, making the solution simply $ y = e^t $.
The analytic solution is not required, it is just that it is a perfect guide for us to evaluate whether our solution make sense. Now, looking up the Runge-Kutta equations, we have
$ f_1 = f(t_n, y_n) $
$ f_2 = f(t_n + \frac{\Delta t}{2}, y_n + \frac{\Delta t}{2} f_1) $
$ f_3 = f(t_n + \frac{\Delta t}{2}, y_n + \frac{\Delta t}{2} f_2) $
$ f_4 = f(t_n + \Delta t, y_n + \Delta t f_3) $
Next, we substitute $ f(t, y) = y $ in the expressions above, then we get:
$ f_1 = y_n $
$ f_2 = y_n + \frac{\Delta t}{2} f_1 $
$ f_3 = y_n + \frac{\Delta t}{2} f_2 $
$ f_4 = y_n + \Delta t f_3 $
Excel will just happy to crank those answers for us now.
The final answer is
$ f_1 = 1 $
$ f_2 = 2 $
$ f_3 = 3 $
$ f_4 = 7 $
$ y(2) = 7 $.
With excel, I fiddled around the parameter. In particular, I tried to tune $ \Delta t $ to 0.1 and iterate 20 times, the result has $ 1.1 \times 10^{-5} $ error only. It is in fact quite accurate.
As an aside to the analytic solution - the integral of $ \int{\frac{1}{y}dy} = \log{y} $ only make sense when $ y > 0 $. To make sense of cases when $ y < 0 $, we can take the sign out first before the integration and the expression become $ \log|y| = sign(y)t + C_1 \implies e^{|y|} = e^{|sign(y)|}e^{t + C_1} \implies e^{y} = e^{t + C_1} $ and the rest follows as is.
Walk through one time-step of 4th-order Runge-Kutta with simple differential equation system $y'=y$, $y(0)=1$ and $\Delta t=2$.
Identify the correct values for f1; f2; f3; f4 and y(2).
Solution:
It is always good to know the solution to the differential equation first, in this case it is really easy.
$ \begin{eqnarray*} \frac{dy}{dt} &=& y \\ \frac{1}{y}\frac{dy}{dt} &=& 1 \\ \int{\frac{1}{y}\frac{dy}{dt}dt} &=& \int{1dt} \\ \log y &=& t + C_1 \\ y &=& e^{t + C_1} \\ &=& C_2e^t \\ \end{eqnarray*} $
Now the initial condition decides $ C_2 = 1 $, making the solution simply $ y = e^t $.
The analytic solution is not required, it is just that it is a perfect guide for us to evaluate whether our solution make sense. Now, looking up the Runge-Kutta equations, we have
$ f_1 = f(t_n, y_n) $
$ f_2 = f(t_n + \frac{\Delta t}{2}, y_n + \frac{\Delta t}{2} f_1) $
$ f_3 = f(t_n + \frac{\Delta t}{2}, y_n + \frac{\Delta t}{2} f_2) $
$ f_4 = f(t_n + \Delta t, y_n + \Delta t f_3) $
Next, we substitute $ f(t, y) = y $ in the expressions above, then we get:
$ f_1 = y_n $
$ f_2 = y_n + \frac{\Delta t}{2} f_1 $
$ f_3 = y_n + \frac{\Delta t}{2} f_2 $
$ f_4 = y_n + \Delta t f_3 $
The final answer is
$ f_1 = 1 $
$ f_2 = 2 $
$ f_3 = 3 $
$ f_4 = 7 $
$ y(2) = 7 $.
With excel, I fiddled around the parameter. In particular, I tried to tune $ \Delta t $ to 0.1 and iterate 20 times, the result has $ 1.1 \times 10^{-5} $ error only. It is in fact quite accurate.
As an aside to the analytic solution - the integral of $ \int{\frac{1}{y}dy} = \log{y} $ only make sense when $ y > 0 $. To make sense of cases when $ y < 0 $, we can take the sign out first before the integration and the expression become $ \log|y| = sign(y)t + C_1 \implies e^{|y|} = e^{|sign(y)|}e^{t + C_1} \implies e^{y} = e^{t + C_1} $ and the rest follows as is.
No comments:
Post a Comment