My Python code takes too long to compute! Can I use numpy to calculate this faster? If so, how? -


I aim to calculate the motion of the planets using the Verlet algorithm.

The problem is, the code takes approximately 30 minutes to complete the whole cycle. This is basic calculation so I do not know why it is taking so long

I have read a bit around and using numpy Need to be fast?

How can I apply it? Also, this full circle is coming and should stop at 0 (or 2 * pi * r_earth , if this distance is counted, it stops)

  grav = 6.673481 * (10 * * -11) 11 6.673481e- # = # A direct path m_sun = 1.989 * (10 ** 30) # = 1.989e + 30 m_earth = 5.972 * (10 ** 24) # = 5.972e + 24 r_earth = 14 9.59, 787 * (10 ** 9) # = 1.4959787e + 11 def verlet_v (prev_v, prev_f, mass): current_v = (prev_v + (prev_f / month)) print "new velocity:% f"% return current_v current_v def verlet_x (prev_x, Current_v) : Current_x = prev_ X + current_v print "new position:% f"% current_x return current_x verlet_v (20, 50, 3) v = 29.8 * (10 ** 3) # = 2. 9 8 + 04 x = 0 f = (-grav * (Abbreviated (m_earth * m_sun) / r_earth ** 2)) v_history = [] x_history = [] while (stomach (x)> (-0.1)): # ABS (& lt; _anything_ & gt;) is always & Gt; -0.1 Print "Mod (x):% f"% abs (x) Print "range:% f"% (0) v = verlet_v (v, f, m_earth) x = verlet_x (x, v) v_history.append ( V) x_history.append (x) print v_history print x_history    

It seems that you 'Then gets stuck in an infinite loop.

abs (x) gives the full value of a number that is always positive. This means that it will never be less than -0.1 , so your loop will never end.

You should either have abs (x) or -0.1 and more.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -