Runge-Kutta using Numerical Recipes

In summary, you need to write a subroutine named 'derivs' that calculates the right-hand sides of your equations for the derivatives.
  • #1
Vrbic
407
18
Hello,
I try to solve a system of ODE's by Runge-Kutta method from here: https://websites.pmc.ucsc.edu/~fnimmo/eart290c_17/NumericalRecipesinF77.pdf, page 704 in the book (not pdf). Bellow is also a code. In function rk4dumb I don't understand how are implemented differential equations. Input are just initial conditions, steps, amount of equations and function for differentiation. How may I input some real problem there? I track subroutine rk4 it has to be in first input, but the value (v) is taken as a new variable in this subroutine. So I'm a bit confused. Please advise me :-)
Thank you all.
 
Technology news on Phys.org
  • #2
First I would advise you to post the code to which you are referring ;)

[ use the insert (+) -> code tool, for best results]
 
  • #3
Ahh-- nevermind, I see the code now in the link. Do you have a particular system of ODEs in mind?
 
  • #4
lewando said:
First I would advise you to post the code to which you are referring ;)

[ use the insert (+) -> code tool, for best results]
The code is in pdf link which I add (pages 706-708). I don't understand how to use it. I rewrite it as subroutines and I have two functions on the paper and think how to implement it. I know Runge-Kutta but mostly there isn't derivative but function f(x,y) (dy/dx=f(y,x)). Now I'm lost.
 
  • #5
lewando said:
Ahh-- nevermind, I see the code now in the link. Do you have a particular ODE in mind?
I would like to prepare generally. I have system let's say: dy/dx=f(x,y,z) and dz/dx=g(x,y,z). Where I input functions f and g?
 
  • #6
I am constrained presently. See if this helps for now: https://epublications.bond.edu.au/cgi/viewcontent.cgi?article=1130&context=ejsie
 
  • #7
Temporarlly out of my constraint (but not for long)-- so the basic concept is running the rk4 with dy/dx to get a Δy. Then do rk4 with dz/dx to get Δz. Now you have a new y and a new z. Repeat the process.
 
  • #8
Vrbic said:
I have system let's say: dy/dx=f(x,y,z) and dz/dx=g(x,y,z). Where I input functions f and g?
See pages 706-707.

You need to write a subroutine named 'derivs' that calculates the right-hand sides of your equations for the derivatives. First, to make things less confusing, re-name your dependent variables so

dy/dx = f(x,y,z) ---> dy1/dx = f(x,y1,y2)
dz/dx = g(x,y,z) ---> dy2/dx = g(x,y1,y2)

Your subroutine 'derivs(x,y,dydx)' receives the value of x and the two y's at which the derivatives are calculated. Note that y and dydx are both arrays, with length 2. y(1) = y1 and y(2) = y2. The subroutine must calculate dydx(1) = dy1/dx = f(x,y1,y2) and dydx(2) = dy2/dx = g(x,y1,y2), which will be returned to the subroutine 'rk4'.
 
  • Like
Likes Vrbic and DrClaude
  • #9
jtbell said:
See pages 706-707.

You need to write a subroutine named 'derivs' that calculates the right-hand sides of your equations for the derivatives. First, to make things less confusing, re-name your dependent variables so

dy/dx = f(x,y,z) ---> dy1/dx = f(x,y1,y2)
dz/dx = g(x,y,z) ---> dy2/dx = g(x,y1,y2)

Your subroutine 'derivs(x,y,dydx)' receives the value of x and the two y's at which the derivatives are calculated. Note that y and dydx are both arrays, with length 2. y(1) = y1 and y(2) = y2. The subroutine must calculate dydx(1) = dy1/dx = f(x,y1,y2) and dydx(2) = dy2/dx = g(x,y1,y2), which will be returned to the subroutine 'rk4'.
Thaaaaaank you very much, now I understand. I thought that "derivs" is an ordinary function for general derivatives.
Thank you all, solved.
 
  • Like
Likes jtbell

Related to Runge-Kutta using Numerical Recipes

1. What is "Runge-Kutta using Numerical Recipes"?

"Runge-Kutta using Numerical Recipes" is a numerical method used for solving ordinary differential equations. It is based on the fourth-order Runge-Kutta method and is implemented using algorithms from the book "Numerical Recipes" by William H. Press, Saul A. Teukolsky, William T. Vetterling, and Brian P. Flannery.

2. How does Runge-Kutta using Numerical Recipes work?

This method works by breaking down a differential equation into smaller steps and approximating the solution at each step. It uses a weighted average of several intermediate approximations to improve the accuracy of the final result.

3. What are the advantages of using Runge-Kutta using Numerical Recipes?

One of the main advantages of this method is its high accuracy. It is also a versatile method that can be used to solve a wide range of differential equations. Additionally, the algorithms from "Numerical Recipes" are well-tested and widely used, making them a reliable choice for solving differential equations.

4. Are there any limitations to using Runge-Kutta using Numerical Recipes?

Like any numerical method, Runge-Kutta using Numerical Recipes has some limitations. It may not be suitable for solving certain types of differential equations, such as stiff equations. It also requires a significant amount of computational resources, making it less efficient for large-scale problems.

5. How can I implement Runge-Kutta using Numerical Recipes?

The algorithms for Runge-Kutta using Numerical Recipes can be found in the book "Numerical Recipes" or in various online resources. They can be implemented in various programming languages, such as C, C++, and Fortran. It is important to carefully follow the steps and equations provided in order to accurately implement the method.

Similar threads

  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
13
Views
2K
  • Programming and Computer Science
Replies
15
Views
2K
Replies
61
Views
1K
Replies
9
Views
2K
  • Programming and Computer Science
Replies
7
Views
2K
  • Programming and Computer Science
Replies
6
Views
2K
  • Programming and Computer Science
Replies
5
Views
2K
  • Programming and Computer Science
Replies
8
Views
3K
  • Programming and Computer Science
Replies
4
Views
7K
Back
Top