Solving 4th Order Runge-Kutta w/ dy/dt = y, y(0)=1

Click For Summary
SUMMARY

The discussion focuses on solving the first-order ordinary differential equation (ODE) dy/dt = y using the fourth-order Runge-Kutta (RK4) method with the initial condition y(0) = 1. The RK4 algorithm is detailed, including the calculations for k(1), k(2), k(3), and k(4), which are essential for advancing the solution one step forward by a specified step size h. The participants clarify the evaluation of the function f at specific points and emphasize the importance of understanding the basic principles of numerical methods before applying RK4.

PREREQUISITES
  • Understanding of first-order ordinary differential equations (ODEs)
  • Familiarity with the Runge-Kutta method, specifically RK4
  • Basic knowledge of numerical methods for solving differential equations
  • Ability to perform function evaluations and substitutions in mathematical expressions
NEXT STEPS
  • Learn the implementation of the Runge-Kutta method in Python using libraries like NumPy
  • Study the Euler method as a simpler alternative to RK4 for solving ODEs
  • Explore error analysis in numerical methods to understand the accuracy of RK4
  • Investigate other numerical methods for solving higher-order ODEs
USEFUL FOR

Students, mathematicians, and engineers interested in numerical analysis and solving ordinary differential equations using advanced methods like RK4.

kmeado07
Messages
40
Reaction score
0

Homework Statement



Use the fourth order Runge-Kutta formula to advance the differential equation:
dy/dt = y with y(0)=1 forward one step h. That is find y(h).


Homework Equations





The Attempt at a Solution



The Runge-Kutta formula is:
x(i+1)=x(i)+h/6 [k(1)+2k(2)+2k(3)+k(4)]

where,
k(1)=f[x(i),t(i)]
k(2)=f[x(i)+1/2 hk(1), t(i)+1/2 h]
k(3)=f[x(i)+1/2 hk(2), t(i)+1/2h]
k(4)=f[x(i)+hk(3),t(i)+h]

I have no idea how to continue though, so any help would be great! thanks
 
Physics news on Phys.org
A first-order ODE is given as,

dy/dx = f(x,y)

this is the definition. So when one states, f(x_i,y_i), this simply means, evaluate the first-order derivative at x_i and y_i.

This is how the method breaks down:

The general form of the RK4 algorithm is given as,<br /> \begin{equation}\begin{split} <br /> k_{1}&amp;=f(x_{i},y_{i})\\<br /> k_{2}&amp;=f(x_{i}+\dfrac{1}{2}h, y_{i}+\dfrac{1}{2}k_{1}h)\\<br /> k_{3}&amp;=f(x_{i}+\dfrac{1}{2}h,y_{i}+\dfrac{1}{2}k_{2}h)\\<br /> k_{4}&amp;=f(x_{i}+h,y_{i}+k_{3}h)\\<br /> y_{i+1}&amp;=y_{i}+\dfrac{1}{6}\cdot(k_{1}+2k_{2}+2k_{3}+k_{4})\cdot h<br /> \label{eq:}<br /> \end{split}\end{equation}

Simplified as eight equations,<br /> \begin{equation}\begin{split} <br /> k_1&amp;=f(x_i,y_i)\\<br /> z_1&amp;=y_i+\dfrac{1}{2}k_{1}h\\<br /> k_2&amp;=f(x_{i}+\dfrac{1}{2}h, z_1)\\<br /> z_2&amp;=y_i+\dfrac{1}{2}k_{2}h\\<br /> k_3&amp;=f(x_{i}+\dfrac{1}{2}h, z_2)\\<br /> z_3&amp;=y_i+k_{3}h\\<br /> k_4&amp;=f(x_{i}+h, z_3)\\<br /> y_{i+1}&amp;=y_i+\left(\dfrac{h\cdot(k_1+2(k_2+k_3)+ k_4)}{6}\right)<br /> \label{eq:}<br /> \end{split}\end{equation}<br />

Say for example you are given, y&#039;=(-y)ln(y),\;\;y(0)=0.5.

Hence,
f(x_0,y_0)=(-0.5)\cdot ln(0.5)

In this example, it only varied in terms of y. However, you could be faced with an ODE such as y&#039;=4e^{0.8x}-0.5y, in which case you need to take care how you substitute in the 'x' value. For the x_i+\dfrac{1}{2}h bits, you need to evaluate it at x_{i+1}=x_i+\dfrac{1}{2}h.

For example, if x_0=0 and h=0.5, then x_1=0+\dfrac{1}{2}(0.5)=0.25.

Hope this helps...
 
thankyou very much for that...i understand all of what you have said.

So i found for my equation that f[t(0),y(0)] = 1, since y'=y and y(0)=1

Im still slightly confused as to how to find y(h)?
 
How do i find what k(1) - k(4) is? Do i substitute anything in for h?

Also what are the value for t(i) and y(i)?
 
You shouldn't jump to using RK4 if you don't understand the basics. Try using the Euler method (it's basically a first-order RK). You also need to know the stepsize 'h'. This is given with questions,

y_{i+1}=y_i+hf(x_i,y_i)

As for your question, y'=y, you can ignore the x or 'time' component as it were, as it only varies in y.

The first RK4 application would be, note y_0=y(0)=1,

k_1 = f(0, 0) =1
k_2 = y_0+0.5*k_1*h
k_3 = y_0+0.5*k_2*h
k_4 = y_0+k_3*h

Hence,
y_1=y_0+\left(\dfrac{h*(k_1+2(k_2+k_3)+k_4)}{6}\right)

For the next iteration, use y_1 to start off :)
 

Similar threads

  • · Replies 14 ·
Replies
14
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 65 ·
3
Replies
65
Views
8K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
1K
Replies
2
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K