在python中的简单重力列车 [英] simple gravity train in python

查看:64
本文介绍了在python中的简单重力列车的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写一个程序简单描述苹果通过地球的运动,或者我们称之为重力列车,请参阅(维基百科的重力列车)通过超物理学的重力列车

http://hyperphysics.phy-astr.gsu.edu/ hbase / mechanics / earthole.html [ ^ ]



我想在时间内绘制移动速度和位置。



这是我制作的代码,但答案错误(速度和时间错误)。虽然我使用正确的方程式下降身体方程式维基百科 https:// en .wikipedia.org / wiki / equations_for_a_falling_body [ ^ ]

我得到的速度和距离值非常大我错了什么?在此先感谢Max



**我必须拥有的价值时间必须等于2530.30秒(接近42.2分钟)最高时速约为7 900米秒(28440公里/小时)。



I want to write a program describes in simple the movement of the apple through the earth, or what we call Gravity train ,see (Gravity train by wikipedia) Gravity train by hyperphysics
http://hyperphysics.phy-astr.gsu.edu/hbase/mechanics/earthole.html[^]

I want to draw movement speed and postion in the time.

This is my code that I made, but I got wrong answer ( wrong value for speed and time). although I used right the equations for a falling body falling body Equations wikipedia https://en.wikipedia.org/wiki/Equations_for_a_falling_body[^]
the value for velocity and distance that I got is very big what is my wrong ? Thanks in advance Max

**What the value that I must have The time must be equals 2530.30 seconds (nearly 42.2 minutes) The maximum speed is about 7 900 metres per second (28440 km/h).

 # -*- coding: utf-8 -*-
import math
import numpy as np
import matplotlib.pyplot as plt

# Please notice that we assume :air friction is neglected

G = 6.67408 * (10**-11)     # gravitational constant
M = 5.972 * (10**24)        # Earth  Mass in kg
r = 6371000                 # Earth radius per meter
p = 5514                    # Mean Earth density in kg\m3

time = 0   #  the begin time is zero
a=0     #  the begin acceleration g 
v=0
t=0

L_h = [] # list for postion (hight)
L_a = [] # list for acceleration
L_v = [] # list for speed
L_t = [] # list for time

# for_loop in the path that we walk
delta=1000
for h in np.arange(1,2*r,delta):

# (M_effective) is The effective mass of earth that changes when h changes 
# (M_effective) =         new sphere volume       * density
#    M_effective = (4./3) * (math.pi) * ((r-h)**3)   *  p
    M_effective = (4./3) * (math.pi) *   p * (math.pow((r-h),3))


    a = G * M_effective / (r**2)  # (a) is the acceleration 

    if a>0:
        a=a
        t=t+math.sqrt(2*delta/a)
        v=v+math.sqrt(2*delta*a)
    else:
        a=a
        t=t + math.sqrt(2*delta/(abs(a))) 
        v=v - math.sqrt(2*delta*(abs(a)))


    L_h.append(h)
    L_t.append(t)
    L_v.append(v)
    L_a.append(a)




plt.subplot(121) 
plt.title("Velocity ")  
plt.xlabel("Time ") 
plt.ylabel("Velocity m/s") 
plt.plot(L_t, L_v, 'g-')


plt.subplot(122)
plt.title("distance ") 
plt.xlabel("Time ") 
plt.ylabel("distance  m") 
plt.plot(L_t, L_h, 'b-')

plt.tight_layout()


plt.figure(2)
plt.plot(L_t, L_a , 'b-')
plt.title("acceleration in tijd") 
plt.xlabel(" Time s") 
plt.ylabel("acceleration (a) m/ss") 


plt.show()
#Gravity train
#The travel time equals 2530.30 seconds (nearly 42.2 minutes),
#For a train that goes directly through the center of the Earth, the maximum speed is about 7 900 metres per second (28440 km/h).

推荐答案

这可能是一个数学问题而不是python问题。如果python是你的计算器,它是一个很好的计算器。



如果您的速度太高或太低,或者时间过长,它的输入或设置。



您似乎偏离了第一个Web链接示例,通过计算有效质量,这不是在网站上计算的。
This may be more of a math problem than a python problem. If python is your calculator, its a good calculator.

If your velocity is too high or low, or time off, its the inputs, or the setup.

It appear you are deviating from the first web link example, by calculating effective mass, which is not calculated on the web site.


这篇关于在python中的简单重力列车的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆