这是我写在VPython中的代码,到目前为止,我是Vpython的新手,我不是那种在python中经验丰富的,所以请给我一些松懈,我得到的错误是:在Visual Python中模拟轨道时遇到了问题
Traceback (most recent call last): File "C:\Users\Makka Pakka\Documents\Planetary Orbits.py", line 28 SUVAT(EarthInitialV,Distance) File "C:\Users\Makka Pakka\Documents\Planetary Orbits.py", line 4, in SUVAT EarthFinalV.x = sqrt((A.x) + 2*Acceleration*(B.x)) TypeError: unsupported operand type(s) for +: 'float' and 'vector'
from visual import *
def SUVAT(A,B):
EarthFinalV.x = sqrt((A.x) + 2*Acceleration*(B.x))
EarthFinalV.y = sqrt((A.y) + 2*Acceleration*(B.y))
EarthFinalV.z = sqrt((A.z) + 2*Acceleration*(B.z))
GravitationalConstant = 10
Sun = sphere(pos=(0,0,0), radius=10, color=color.red,
make_trail=True)
Earth = sphere(pos=(50,0,0), radius=5, color=color.yellow,
make_trail=True)
Sun.mass = 50
Earth.mass = 10
EarthInitialV = vector(5,5,5)
EarthFinalV = vector(0,0,0)
while 1 != 2:
Distance = Earth.pos - Sun.pos
GravitationalEquation = (GravitationalConstant*Sun.mass*Earth.mass)*Distance/mag(Distance)**3
Acceleration = GravitationalEquation/Earth.mass
SUVAT(EarthInitialV,Distance)
Earth.x.pos = Earth.x.pos + EarthFinalV.x
Earth.y.pos = Earth.y.pos + EarthFinalV.y
Earth.z.pos = Earth.z.pos + EarthFinalV.z
您碰到什么问题?你用上面的代码观察什么?在你的问题中回答这些问题将有助于获得更多答复。 – nbryans
哦对不起,我必须包括,现在编辑它 –