RK4 Solver Issue: Shoot the Moon with C Program

  • Thread starter Illuminati
  • Start date
  • Tags
    Rk4
In summary, the speaker is seeking help with their 4th order Runge-Kutta program for shooting the moon with a spacecraft. They have written the program in C and attached the file. They are looking for someone who is more familiar with C to take a look and see what the issue might be. They have also attached a couple of different methods and suggest using shoot_the_moon3.c for the best results. They mention that the spacecraft is not behaving as expected and may be due to an initial value problem or a rounding error.
  • #1
Illuminati
5
0
Hey Folks,

So I've been making an 4th order Runge-Kutta program for finding a way to shoot the moon with a spacecraft . However for some reason the RK4 part of the program does not work and I cannot figure it out.

I've written it in C and attached the file. If someone who is more well versed in C could take a look at it and let me know what I'm screwing up I would be greatly appreciative.

Thanks!

Edit: I've attached a couple different methods to this post. If viewing try using shoot_the_moon3.c, it should have a working .plt file to output a .png of the data
 

Attachments

  • Shoot the Moon.zip
    22.6 KB · Views: 219
Last edited:
Technology news on Phys.org
  • #2
I suppose I should add that the spacecraft is supposed to have some kind of circular orbit, instead it acts more like a massed spring

it might be an initial value problem
 

1. What is an RK4 solver?

An RK4 solver is a numerical method used to approximate the solution to a differential equation. It uses the Runge-Kutta method, specifically the fourth-order Runge-Kutta method, to calculate the solution at discrete time steps.

2. How does the RK4 solver work?

The RK4 solver works by using four intermediate calculations to estimate the slope of the solution at each time step. These estimates are then used to calculate the final solution. The process is repeated at each time step until the desired accuracy is achieved.

3. What is the "shoot the moon" problem?

The "shoot the moon" problem is a mathematical problem that involves determining the initial velocity and angle needed for a projectile to hit a target at a given distance. It is commonly used as a test case for numerical solvers, including the RK4 solver.

4. How is the RK4 solver used to solve the "shoot the moon" problem in a C program?

To solve the "shoot the moon" problem in a C program using the RK4 solver, the initial conditions (such as the position and velocity of the projectile) and the target distance must be defined. The RK4 solver is then used to calculate the position and velocity of the projectile at each time step until it reaches the target distance. The initial angle and velocity can be adjusted until the target distance is reached with a desired level of accuracy.

5. What are some common issues that may arise when using the RK4 solver to solve the "shoot the moon" problem?

One common issue that may arise is the selection of an appropriate time step. If the time step is too large, the solution may be inaccurate. Another issue could be the initial conditions being too far from the target distance, making it difficult to achieve the desired accuracy. Additionally, rounding errors and computer precision can also affect the accuracy of the solution.

Similar threads

  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
22
Views
3K
  • Programming and Computer Science
Replies
8
Views
3K
  • Programming and Computer Science
Replies
8
Views
1K
  • Astronomy and Astrophysics
Replies
4
Views
1K
  • Programming and Computer Science
Replies
13
Views
4K
  • Programming and Computer Science
Replies
17
Views
2K
Replies
1
Views
965
  • Science and Math Textbooks
Replies
1
Views
929
  • Programming and Computer Science
Replies
5
Views
2K
Back
Top