问题描述
我想写一个程序简单描述苹果通过地球的运动,或者我们称之为重力列车,请参阅(维基百科的重力列车)通过超物理学的重力列车
[]
我想在时间内绘制移动速度和位置。
这是我制作的代码,但答案错误(速度和时间错误)。虽然我使用正确的方程式下降身体方程式维基百科 []
我得到的速度和距离值非常大我错了什么?在此先感谢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中的简单重力列车的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!