I'm trying to simulate moon orbit around earth, my moon is broken.

In summary: End SubPublic Sub Moon_Angle( ByVal x As Double, ByVal y As Double) x = x + (y - 385000000) / 1023 y = y + 385000000 End SubEnd Sub
  • #1
xzbobzx
10
0

Homework Statement



Alright, this is probably going to be a long one.

For a school project I am trying to simulate (in 2D) our moon's orbit around the earth, to eventually simulate a spaceship doing a hohmann transfer between LEO and LLO whilst being affected by both the Earth's gravity and the moon's gravity.

I am not trying to simulate/solve a three body problem. And the simulation is more of a back of the envelope simulation than a true earth-moon system simulation, but it will serve it's purpose:
The Earth is not affected by the moon.
The moon is only affected by the Earth's gravitational pull and its initial velocity.

The given variables/data/setup:
- I have a coordinate system X and Y, Y goes up, X goes right. The (static) Earth is located at the centre.
- Our moon is located at Y = 385000000 m (the moon's mean orbital distance is 385000 km)
- Moon initial velocity is X = 1023 m/s (the moon's mean orbital velocity is 1.023 km/s)
- Moon mass is irrelevant for now as I'm doing it all based on acceleration, and because the Earth is static.
- Earth mass is 5.97219*10^24 kg.
- A Timestep of 1 second.

Homework Equations



[itex]g = -\frac{GM}{r^2}[/itex]

[itex]g =[/itex] gravitational acceleration
[itex]G =[/itex] gravitational constant
[itex]M =[/itex] Earth mass
[itex]r =[/itex] orbit radius

The Attempt at a Solution



I set up a Microsoft excel project and began coding an macro do to all my heavy lifting:

Code:
    Public moon_px As Double 'Position.x (m)
    Public moon_py As Double 'Position.y
    Public moon_pm As Double 'Position Magnitude
    
    Public moon_vx As Double 'Velocity.x (m/s)
    Public moon_vy As Double 'Velocity.y
    Public moon_vm As Double 'Velocity Magnitude
    
    Public moon_ax As Double
    Public moon_ay As Double
    Public moon_am As Double
    
    Public angle As Double 'Angular position relative to earth, 0 = "north", 180 = "south" (degrees)
    
    Public gravity As Double
    Public Earth As Double
        
    Public Timestep As Double '(s)
    Public Time As Double
    
    Public Iterations As Double
    Public i As Double

'---------

Sub TransLunarInjection()
            
    moon_px = Cells(2, 2).Value
    moon_py = Cells(3, 2).Value
    moon_vx = Cells(4, 2).Value
    moon_vy = Cells(5, 2).Value
    moon_ax = 0
    moon_ay = 0
    Time = Cells(6, 2).Value
    Timestep = Cells(7, 2).Value
    Iterations = Cells(8, 2).Value
    i = 1
        
    gravity = 6.67384 * 10 ^ -11
    Earth = 5.97219 * 10 ^ 24
    
    moon_vm = Sqr(moon_vx ^ 2 + moon_vy ^ 2)
    moon_pm = Sqr(moon_px ^ 2 + moon_py ^ 2)
    
    'moon_ax = 0
    'moon_ay = 0
        
    Do While i <= Iterations
        
        Call Moon_Angle(moon_px, moon_py)
        
        moon_vm = Sqr(moon_vx ^ 2 + moon_vy ^ 2)
        moon_pm = Sqr(moon_px ^ 2 + moon_py ^ 2)
        
        moon_ax = Sin(angle) * ((gravity * earth) / (moon_pm ^ 2)) * -1 * Timestep
        moon_ay = Cos(angle) * ((gravity * earth) / (moon_pm ^ 2)) * -1 * Timestep
        
        moon_vx = moon_vx + moon_ax
        moon_vy = moon_vy + moon_ay
        
        moon_px = moon_px + moon_vx
        moon_py = moon_py + moon_vy
        
        Cells(i + 1, 4).Value = Time
        Cells(i + 1, 5).Value = angle
        Cells(i + 1, 6).Value = moon_pm
        Cells(i + 1, 7).Value = moon_vm
        Cells(i + 1, 8).Value = moon_ax
        Cells(i + 1, 9).Value = moon_ay
        Cells(i + 1, 10).Value = Sqr(moon_ax ^ 2 + moon_ay ^ 2)
        Cells(i + 1, 11).Value = moon_vx
        Cells(i + 1, 12).Value = moon_vy
        Cells(i + 1, 13).Value = moon_px
        Cells(i + 1, 14).Value = moon_py
        
        Time = Time + Timestep
        
        i = i + 1
        
    Loop
        
End Sub

'---------

Sub Moon_Angle(x As Double, y As Double)

    If y > 0 And x = 0 Then angle = 0
    If y < 0 And x = 0 Then angle = 180
    If x > 0 And y = 0 Then angle = 90
    If x < 0 And y = 0 Then angle = 270
    If x = 0 And y = 0 Then angle = 0
    If y > 0 And x > 0 Then angle = Atn(x / y)
    If y < 0 And x > 0 Then angle = 90 + Atn(y / x) * -1
    If y < 0 And x < 0 Then angle = 180 + Atn(x / y)
    If y < 0 And x > 0 Then angle = 270 + Atn(y / x) * -1

End Sub

So what this does, step by step:
1. Calculate the moon's angle relative towards the Earth using simple trigonometry.
2. Calculate the moon's acceleration for both the X and the Y axis, using trigonometry and the gravitational acceleration equation.
3. Apply acceleration to velocity.
4. Apply velocity to position.
5. Print all variables.
6. Advance time by 1 second.
7. Loop.

This doesn't work.

(At first I even planned to do an RK4 implementation but that was a complete nightmare.)

A snippet of my printed values:
Code:
    Time = 0s:
Angle = 0°
Distance = 385000000m
Acceleration X = 0m/s^2
Acceleration Y = -0,002688982324817m/s^2
Velocity X = 1023m/s
Velocity Y = -0,002688982324817m/s
Position X = 1023m
Position Y = 384999999,997311m

    Time = 3600s: (after one hour)
Angle = 0,00956571126379358°
Distance = 385000184,85925m
Acceleration X = -0,0000257216115406931m/s^2
Acceleration Y = -0,00268885671887548m/s^2
Velocity X = 1022,95368785554m/s
Velocity Y = -9,6828746017381m/s
Position X = 3683767,39436805m
Position Y = 384982561,007074m

Now I'm not a rocket scientist, but I do suppose that after one hour, at 1km/s, our moon should have moved along the Y axis a bit more than 17.438km.

After around 7 days the moon should be at Y = 0, at 17.5km/h I doubt it will traverse 385000km

Our X position has moved a lot, however, and extrapolating this we'll see the moon move right indefinitely, whilst only going down a relatively small amount. Like this:

n6WyM7D.png

(Black arrow what it is currently doing and brown arrow what it should be doing. I also uploaded it as an attachment for future visitors should this image go down.)

I believe that my calculations are wrong. Or at least the vector implementation of said calculations. (I checked the gravitational acceleration at ground level and it was a steady 9.81m/s^2)

I was wondering if anyone could help me get on track with what I'm doing wrong, or what I should be doing instead. I'm also open to the possibility that my entire idea of how orbital physics should work is off, but if anyone could help me out then that would be greatly appreciated.

Thank you for your time!
 

Attachments

  • norbit2.png
    norbit2.png
    2.4 KB · Views: 571
Last edited:
Physics news on Phys.org
  • #2
moon_px = moon_px + moon_vx

Where is the timestep?

Note: this is the first thing that caught my attention, doesn't mean it is the only one, doesn't mean it is the most important one.
 
  • #3
Borek said:
Where is the timestep?

Note: this is the first thing that caught my attention, doesn't mean it is the only one, doesn't mean it is the most important one.

I placed it in my acceleration calculation as that seemed the most logical place to put it:

moon_ax = Sin(angle) * ((gravity * earth) / (moon_pm ^ 2)) * -1 * Timestep

Do I need a second timestep at the position?
 
  • #4
xzbobzx said:
Do I need a second timestep at the position?

Yes.

[tex]a = \frac {d^2x} {dt^2}[/tex]

You need to multiply twice by Δt.
 
  • #5
Ah okay, that kind of makes sense.

But now I think about it, my timestep is already 1. (I forgot to add this to the main post, doing so now) I don't think that another multiply by 1 is going to solve this.

Is the concept behind what I'm doing (from what you can tell) correct, by the way? I've toyed with the thought that what I'm doing is just an entirely wrong approach in the first place.
 
  • #6
I assume that the calls to Cells(i, j) return the contents of the spreadsheet cell at row i and column j.

Perhaps you are running up against a limit of the spreadsheet. Spreadsheets usually have a set maximum number of rows and columns, and at one step per second you will probably quickly exceed those limits.
 
  • #7
tms said:
I assume that the calls to Cells(i, j) return the contents of the spreadsheet cell at row i and column j.

Perhaps you are running up against a limit of the spreadsheet. Spreadsheets usually have a set maximum number of rows and columns, and at one step per second you will probably quickly exceed those limits.

I've tried ramping the Interations up to a million, and even though it took 10 minutes to get it all calculated I could scroll down aaaallll the way to the bottom.

In fact I just checked: http://office.microsoft.com/en-001/...its-HP010342495.aspx?CTT=5&origin=HP005199291

I was exactly 48,576 iterations shy of hitting the limit. One more zero and I would've been a dead man.
 
  • #8
The last time I tried using Excel the limit was 65536 rows, I think. Even with the increase, there will only be enough to do about half a revolution of the Moon. Changing the time set to a minute probably won't hurt the accuracy enough to matter.
 
  • Like
Likes 1 person
  • #9
Angles in Excel are measured in radians so sub Moon_Angle will return the wrong values unless x and y are both greater than zero (which they are for the first 7 days, so this is not your problem).

If you are assuming that the moon's orbit is circular then you should just use a formula for uniform circular motion. If you want to calculate the moon's orbit then you need to use different and more accurate initial conditions.
 
  • #10
MrAnchovy said:
Angles in Excel are measured in radians so sub Moon_Angle will return the wrong values unless x and y are both greater than zero (which they are for the first 7 days, so this is not your problem).

If you are assuming that the moon's orbit is circular then you should just use a formula for uniform circular motion. If you want to calculate the moon's orbit then you need to use different and more accurate initial conditions.

Now you mention the radians things: that might actually be a problem. I'll have to look into that at school tomorrow.

And for the moon's orbit, meh :D, I don't really care that the moon isn't flying a perfect circular orbit, I just want a body that adheres to gravitational acceleration properly.
In my final simulation I'll probably just hardcode the moon to follow a set path, I just need to figure out where my eventual spacecraft will end up if I send it hurling to the moon at a variable speed. And for that simulation I need the acceleration equations.
...I think.
 
  • #11
As a general rule, all trig functions (sin, cos, tan) take radian measure for their argument unless specifically stated otherwise in the documentation, whether it is for Excel, another brand of spreadsheet, or most computing languages. About the only devices which accept degree arguments for trig functions as a default are calculators.
 
  • Like
Likes 1 person
  • #12
xzbobzx said:
Now you mention the radians things: that might actually be a problem. I'll have to look into that at school tomorrow.

It "is" a problem, not "might be" a problem! It might not be the only problem, of course.

You don't need all those tests in your moon angle routine. The "atan2" function will sort it all out for you. http://office.microsoft.com/en-gb/excel-help/atan2-HP005208991.aspx
 
Last edited by a moderator:
  • Like
Likes 1 person
  • #13
SteamKing said:
As a general rule, all trig functions (sin, cos, tan) take radian measure for their argument unless specifically stated otherwise in the documentation, whether it is for Excel, another brand of spreadsheet, or most computing languages. About the only devices which accept degree arguments for trig functions as a default are calculators.

That's a very good rule to follow, I had no idea. Thank you!


AlephZero said:
It "is" a problem, not "might be" a problem! It might not be the only problem, of course.

You don't need all those tests in your moon angle routine. The "atan2" function will sort it all out for you. http://office.microsoft.com/en-gb/excel-help/atan2-HP005208991.aspx

Hahaha yeah, I've been shot in the foot by trig functions in programming before. And I didn't know about atan2, that's going to be very useful!
 
Last edited by a moderator:
  • #14
Note also that you have set up your directions differently from what the trig functions expect. You have set 0 degrees in the positive y direction, increasing clockwise, while the trig functions expect 0 degrees to be in the positive x direction, increasing counter-clockwise.
 
  • #15
xzbobzx said:
And for the moon's orbit, meh :D, I don't really care that the moon isn't flying a perfect circular orbit, I just want a body that adheres to gravitational acceleration properly.
Then you really need to change the method you are using to integrate the equations of motion. You're basically using Euler's method, which is known to be unstable. Runge-Kutta might indeed be a bit hard to implement in Excel, but the leap-frog method should be as easy as Euler.

For the kind of simulation you want to run, I would follow MrAnchovy's suggestion and just program a circular orbit.
 
  • #16
AlephZero said:
You don't need all those tests in your moon angle routine. The "atan2" function will sort it all out for you. http://office.microsoft.com/en-gb/excel-help/atan2-HP005208991.aspx
The OP is using VBA (a scripting language for Microsoft Office products), which apparently does not have that function.
 
Last edited by a moderator:
  • #17
DrClaude said:
Then you really need to change the method you are using to integrate the equations of motion. You're basically using Euler's method, which is known to be unstable. Runge-Kutta might indeed be a bit hard to implement in Excel, but the leap-frog method should be as easy as Euler.

For the kind of simulation you want to run, I would follow MrAnchovy's suggestion and just program a circular orbit.

I'll have to look into the leapfrog integration. I know Euler is really unstable but it was the only solution I had at hand.

As for the circular orbit. Well yes, I could do that and have my moon perfectly rotate around the earth, but I'm not trying to achieve a perfect round orbit. I'm just using the moon as a staging platform to test if my physics work. You might as well read "moon" as "spaceship".
tms said:
The OP is using VBA (a scripting language for Microsoft Office products), which apparently does not have that function.

Well dang.
I can just replace 90 with PI*0.5, 180 with PI, 270 with PI*1.5, and then later change them back to angles to display the angle. Shouldn't be a big deal, I think.
 
  • #18
tms said:
The OP is using VBA (a scripting language for Microsoft Office products), which apparently does not have that function.

So why does the web page say "Applies to: Excel 2003"?

Atan2 has been in every version of Basic, and most other programming languages, for about 50 years now.

(But I admit the last version of Excel that I actually used was from Office 97.)
 
  • #19
AlephZero said:
So why does the web page say "Applies to: Excel 2003"?

Atan2 has been in every version of Basic, and most other programming languages, for about 50 years now.

I don't know what to think anymore.

I'll try it out tomorrow and come back with results!
 
  • #21
xzbobzx said:
And for the moon's orbit, meh :D, I don't really care that the moon isn't flying a perfect circular orbit, I just want a body that adheres to gravitational acceleration properly.

You're missing the point. If you want to calculate the actual trajectory of the moon you need to start with the position and velocity of the moon at some point on the moon's actual orbit. As you don't have these you would be better off assuming that the moon has a uniform circular orbit.

As for the trig, it is unneccessary anyway. Note that
$$ F_x = -f cos \theta, F_y = - f sin \theta $$ and
$$ x = r cos \theta, y = r sin \theta; r^2 = x^2 + y^2 $$ so we have
$$ F_x = -\frac{fx}{r}, F_y = -\frac{fy}{r} $$ or
$$ A_x = -\frac{Gmx}{r^3}, A_y = -\frac{Gmy}{r^3} $$

VBA sucks for this (and most things). If you haven't got anything better I'd use javascript like this - which confirms that your code actually comes up with OK results in the first quadrant at least.
 
  • #22
tms said:
The OP is using VBA (a scripting language for Microsoft Office products), which apparently does not have that function.

VBA may not have ATAN2 (I haven't checked), but ATAN2 is one of the functions built into Excel itself.

http://office.microsoft.com/en-us/excel-help/math-and-trigonometry-functions-HP005201253.aspx
 
Last edited by a moderator:
  • #23
AlephZero said:
So why does the web page say "Applies to: Excel 2003"?

Atan2 has been in every version of Basic, and most other programming languages, for about 50 years now.

(But I admit the last version of Excel that I actually used was from Office 97.)
Excel itself has the functions ATAN() and ATAN2(), but VBA only has ATN() (note the spelling difference). Don't ask me why; I avoid Office like the plague. Perhaps VBA has it, but I can't find it, and googling finds people saying it doesn't exist.
 
  • #24
xzbobzx said:


Now I'm not a rocket scientist, but I do suppose that after one hour, at 1km/s, our moon should have moved along the Y axis a bit more than 17.438km.

After around 7 days the moon should be at Y = 0, at 17.5km/h I doubt it will traverse 385000km



The calculation is currect. (at least while the moon is in the first quadrant) The acceleration in the Y-direction: 0,002688982324817m/s^2 doesn't vary much in the first hour.

If we pretend it's constant you get Y = (1/2)at^2 = 17.4 km.
 
  • Like
Likes 1 person
  • #25
MrAnchovy said:
You're missing the point. If you want to calculate the actual trajectory of the moon you need to start with the position and velocity of the moon at some point on the moon's actual orbit. As you don't have these you would be better off assuming that the moon has a uniform circular orbit.
I think the OP means to use the circular orbit to test his algorithm before using it to calculate the transfer orbit.
 
  • #26
DrClaude said:
Then you really need to change the method you are using to integrate the equations of motion. You're basically using Euler's method, which is known to be unstable.
Euler's method is not always unstable; it is so only in some circumstances. The thing to do would be to actually test it and see if it is unstable.
 
  • #27
Hurray! The moon works!

Code:
    Public moon_px As Double 'Position.x (m)
    Public moon_py As Double 'Position.y
    Public moon_pm As Double 'Position Magnitude
    
    Public moon_vx As Double 'Velocity.x (m/s)
    Public moon_vy As Double 'Velocity.y
    Public moon_vm As Double 'Velocity Magnitude
    
    Public moon_ax As Double
    Public moon_ay As Double
    Public moon_am As Double
    
    Public angle As Double 'Angular position relative to earth, 0 = "north", 180 = "south" (degrees)
    
    Public gravity As Double
    Public Earth As Double
        
    Public Timestep As Double '(s)
    Public Time As Double
    
    Public Iterations As Double
    Public i As Double
    
    Public Degree As Double
    Public Radian As Double
    Public PI As Double

'---------

Sub DoPrint(thing As Double)

    Cells(i + 1, 4).Value = Round(Time / 60 / 60 / 24, 1)
    Cells(i + 1, 5).Value = Round(angle * Degree, 1)
    Cells(i + 1, 6).Value = Round(moon_pm, 0)
    Cells(i + 1, 7).Value = Round(moon_vm, 1)
    Cells(i + 1, 8).Value = Round(moon_ax, 3)
    Cells(i + 1, 9).Value = Round(moon_ay, 3)
    Cells(i + 1, 10).Value = Round(moon_am, 3)
    Cells(i + 1, 11).Value = Round(moon_vx, 1)
    Cells(i + 1, 12).Value = Round(moon_vy, 1)
    Cells(i + 1, 13).Value = Round(moon_px, 0)
    Cells(i + 1, 14).Value = Round(moon_py, 0)
        
    Cells(i + 1, 16).Value = angle
    Cells(i + 1, 17).Value = Sin(angle)
    Cells(i + 1, 18).Value = Cos(angle)
    
End Sub

'---------

Sub TransLunarInjection()
    
    Degree = 57.2957795
    Radian = 0.0174532925
    PI = 3.14159265359
    
    moon_px = Cells(2, 2).Value
    moon_py = Cells(3, 2).Value
    moon_vx = Cells(4, 2).Value
    moon_vy = Cells(5, 2).Value
    moon_ax = 0
    moon_ay = 0
    Time = Cells(6, 2).Value
    Timestep = Cells(7, 2).Value
    Iterations = Cells(8, 2).Value
    i = 1
        
    gravity = 6.67384 * 10 ^ -11
    Earth = 5.97219 * 10 ^ 24
    
    moon_vm = Sqr(moon_vx ^ 2 + moon_vy ^ 2)
    moon_pm = Sqr(moon_px ^ 2 + moon_py ^ 2)
    moon_am = Sqr(moon_ax ^ 2 + moon_ay ^ 2)
            
    Do While i <= Iterations
        
        If i Mod 1 = 0 Then Call DoPrint(0)
        
        Call Moon_Angle(moon_px, moon_py)
        
        moon_vm = Sqr(moon_vx ^ 2 + moon_vy ^ 2)
        moon_pm = Sqr(moon_px ^ 2 + moon_py ^ 2)
        moon_am = Sqr(moon_ax ^ 2 + moon_ay ^ 2)
        
        moon_ax = Sin(angle) * ((gravity * earth) / (moon_pm ^ 2)) * -1 * Timestep
        moon_ay = Cos(angle) * ((gravity * earth) / (moon_pm ^ 2)) * -1 * Timestep
        
        moon_vx = moon_vx + moon_ax
        moon_vy = moon_vy + moon_ay
        
        moon_px = moon_px + moon_vx * Timestep
        moon_py = moon_py + moon_vy * Timestep

        Time = Time + Timestep
        
        i = i + 0.001
        
    Loop
        
End Sub

'---------

Sub Moon_Angle(x As Double, y As Double)

    If y > 0 And x = 0 Then angle = 0
    If y < 0 And x = 0 Then angle = 180 * Radian
    If x > 0 And y = 0 Then angle = 90 * Radian
    If x < 0 And y = 0 Then angle = 270 * Radian
    If x = 0 And y = 0 Then angle = 0
    If y > 0 And x > 0 Then angle = Atn(x / y)
    If y < 0 And x > 0 Then angle = Atn(x / y) + 180 * Radian
    If y < 0 And x < 0 Then angle = Atn(x / y) + 180 * Radian
    If y > 0 And x < 0 Then angle = Atn(x / y) + 360 * Radian

End Sub

There were a couple of changes I made thanks to you guys:

- I fixed the radian and degrees issue.
- I fixed my "atan2" Moon_Angle function to properly give angle depending on the moon's position.
- I added a second Timestep multiplyer at my position = position + velocity.
- I Changed my Timestep to 60 seconds.

And it works grand!

I also made sure that my code only prints the results every 1000th loop, as otherwise I ended up with about 40000 lines of data just for one orbit. Now it prints one orbit in 40, give or take a few.

And I think that for my current back-of-the-envelope method of doing this simulation Euler integration will be just fine. The moon makes a perfectly neat orbit and ends up right about where it started. I'm sure that if I made this simulation run for a couple million years something would mess up, but most trans-lunar injections (luckily) don't take millions of years.

I've supplied the datasheet of me simulation for you guys to take a look at, and I thank you all. Your help was greatly appreciated!
 

Attachments

  • Moon Orbit Simulation Results Big.pdf
    113.9 KB · Views: 210
  • #28
Made a few small changes to your code:

Sub Moon_Angle(x As Double, y As Double)
angle = WorksheetFunction.Atan2(x, y)
end Sub​
and
moon_ax = -Cos(angle) * ((gravity * earth) / (moon_pm ^ 2))
moon_ay = -Sin(angle) * ((gravity * earth) / (moon_pm ^ 2))

moon_vx = moon_vx + moon_ax * Timestep
moon_vy = moon_vy + moon_ay * Timestep

moon_px = moon_px + moon_vx * Timestep
moon_py = moon_py + moon_vy * Timestep​

Works like a dream: zooms around in 28 days in a near-perfect circle with a timestep of 3600 seconds ! Even after 10000 hours, speed is only 0.5% low.

Enjoyed playing with this, even though I just noticed I was a little too late !:frown:
 
  • #29
xzbobzx said:
Hurray! The moon works!

Code:
    Public moon_px As Double 'Position.x (m)

        
        moon_vx = moon_vx + moon_ax
        moon_vy = moon_vy + moon_ay
        
        moon_px = moon_px + moon_vx * Timestep
        moon_py = moon_py + moon_vy * Timestep
You want to update the vx and vy using the * timestep too !
 
  • #30
Is excel this powerful? I though it's something accountants use for their work. -_-
 
  • #31
BvU said:
Enjoyed playing with this, even though I just noticed I was a little too late !:frown:

Ah well, no worries! Thanks anyway :D

I toyed around with my moon and set the initial position and speed to the moon's perigee and max velocity: http://nssdc.gsfc.nasa.gov/planetary/factsheet/moonfact.html

Ran it like that and I got a very neat eclipse orbit with it's apogee nearly exactly at where our moon's actual apogee is.

Now to start coding my moon ship so I can get a Hohmann transfer underway!


adjacent said:
Is excel this powerful? I though it's something accountants use for their work. -_-

It's got a whole programming language under the hood that can be utilized. Of course, it's not the best qua performance to run an astrophysics simulation, but Excel's all we have at school, and it works perfectly fine!
 
  • #32
BvU said:
You want to update the vx and vy using the * timestep too !

He did, read the code again.
 
  • #33
Borek said:
He did, read the code again.
You're right. I had moved the *timestep down to the vx, vy expression to keep dimension of a in lline with naming and also to get the right values for ax, ay, am in the table. In fact, now I start wondering if the expression for px, py improves if 0.5 * timestep is used instead of *timestep...
 
  • #34
adjacent said:
Is excel this powerful? I though it's something accountants use for their work. -_-
Excel on its own is already extremely powerful. With VBA as programming language with quite some object orientation is powerful squared.

Biggest drawback is that in practice it is the epitome of unstructured programming, so re-use and knowledge transfer are disaster areas.

Having said that, there's an awful lot of science and technology it can be (and is) used for.
 

1. Why is my moon not orbiting around the earth?

There could be several reasons for this issue. It could be due to incorrect initial conditions, such as the moon's position or velocity. It could also be caused by a mistake in the simulation code or incorrect parameters. Double-checking your code and input values can help identify the problem.

2. How can I fix my broken moon in the simulation?

If your moon is not behaving as expected in the simulation, first check for any errors in your code or input values. If everything seems correct, try adjusting the parameters, such as the moon's mass or the gravitational constant, to see if that affects the moon's orbit. You can also try changing the simulation time step to see if that makes a difference.

3. Is it necessary to include the moon's gravitational pull on the earth in the simulation?

Yes, it is important to include the moon's gravitational pull on the earth in the simulation. The moon's gravity affects the earth's orbit around the sun, and therefore, it is a crucial factor in determining the moon's orbit around the earth.

4. How can I make my moon's orbit more realistic in the simulation?

To make your moon's orbit more realistic, you can consider including other factors that affect the moon's orbit, such as the earth's rotation, the gravitational pull of other celestial bodies, and the moon's own rotation. You can also use more accurate values for the parameters, such as the moon's mass and distance from the earth.

5. Can I use the same simulation to model the moon's orbit around other planets?

Yes, you can use the same simulation to model the moon's orbit around other planets. However, you will need to adjust the parameters, such as the planet's mass and distance from the moon, to accurately simulate the orbit. You may also need to consider other factors, such as the planet's rotation and gravitational pull from other bodies, to make the simulation more realistic.

Similar threads

  • Introductory Physics Homework Help
Replies
1
Views
195
  • Introductory Physics Homework Help
Replies
11
Views
763
  • Introductory Physics Homework Help
Replies
2
Views
1K
  • Introductory Physics Homework Help
2
Replies
38
Views
1K
  • Introductory Physics Homework Help
Replies
6
Views
1K
  • Introductory Physics Homework Help
Replies
7
Views
3K
  • Advanced Physics Homework Help
Replies
1
Views
955
  • Introductory Physics Homework Help
Replies
5
Views
4K
  • Introductory Physics Homework Help
Replies
14
Views
2K
  • Introductory Physics Homework Help
2
Replies
43
Views
6K
Back
Top