Jump to content

What's wrong withb my Runge-Kutta approximation?


Recommended Posts

I've been playing this game to practice / learn classical mechanics. Last night, I wrote the Runge-Kutta algorithm in c++ in order to approximate the velocity of a rocket after a given period of time has passed, using a very basic model.

I'm only taking a few things into account:

- time

- constant thrust from the rocket

- constant gravity (not taking into account distance from the surface of kerbin)

- constant atmospheric density (not taking into account altitude)

Using these independent variables, I calculate:

- mass of the rocket given the time

- force of drag on the rocket, given the constant atmospheric density. I calculate the cross-sectional area of the rocket based off the total empty mass. Drag coeffecient is 0.2 Velocity is the velocity at the previous step of the algorithm. I just use the formula on the wiki for drag.

- acceleration based off the constant acceleration due to gravity, the thrust of the rocket, the force of drag, and the mass of the rocket after the given time.

- velocity using the runge-kutta algorithm.

I've built a very simple rocket to test the program. It is nothing more than the starting capsule, an RT-10 solid rocket booster, two modular girder segments, and two mk16 parachutes.

After 28 seconds the program estimates that the velocity is 362.807 m/s. In the game, the velocity is about 555 m/s.

What could be the source of this high error rate? Is using constant gravity and constant atmospheric density going to result in these extremely divergent values? I can post the code, but I figured I'd see if anything jumped out at anyone.

Link to comment
Share on other sites

Without doing a complete analysis (that may require to see the formulae you used to calculate the velocity), two things may have to be considered:

- ISP is variable, the speed of exhaust gases changes with atmosphere density;

- atmospheric density is decreasing with altitude, therefore drag (and that is pretty relevant itself).

Link to comment
Share on other sites

Without doing a complete analysis (that may require to see the formulae you used to calculate the velocity), two things may have to be considered:

- ISP is variable, the speed of exhaust gases changes with atmosphere density;

- atmospheric density is decreasing with altitude, therefore drag (and that is pretty relevant itself).

Thanks for the reply. I was basically guessing, but I figured that without accounting for these two forces (as well as the fact that the force of gravity grows weaker the higher you go), I would still get a reasonably accurate estimation. In your estimation, could these two factors really account for such a vast discrepancy (difference of about 200 m/s after 28 seconds) between the estimated velocity and the actual velocity?

Link to comment
Share on other sites

- ISP is variable, the speed of exhaust gases changes with atmosphere density;

Though in KSP, it's actually the rate of fuel consumption that changes, and the thrust remains constant (reverse of real-world)

That will definitely affect your results, but I think the changing drag with altitude is likely to be a bigger factor

Link to comment
Share on other sites

I think assuming constant atmospheric density is the big mistake. Kerbin's atmosphere falls off surprisingly quickly, with a scale height of 5 km (compared to 8.5 for Earth) meaning that 5 km up the air pressure and thus the drag is just 37% of sea level.

Link to comment
Share on other sites

I think assuming constant atmospheric density is the big mistake. Kerbin's atmosphere falls off surprisingly quickly, with a scale height of 5 km (compared to 8.5 for Earth) meaning that 5 km up the air pressure and thus the drag is just 37% of sea level.

It seems like everyone agrees that this is probably what is throwing the results off. I will incorporate the diminishing atmospheric drag into the model and then come back with my results. Thanks everyone!

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...