import numpy as npimport matplotlibpyplot as plt# Constants SI unitsG = 66743e-11 # gravitational constantm_s = 19885e30 # mass of Sunm_m = 7342e22 # mass of Moonm_mer = 3301e23 # mass of
The error "invalid index to scalar variable" occurs because the variable r0_mer is defined as a scalar value instead of an array.
To fix the error, we need to change the definition of r0_mer from a scalar value to an array.
Replace this line:
r0_mer = 2.44e6 # radius of Mercury
with this line:
r0_mer = np.array([2.44e6, 0]) # radius of Mercury
This will create a 2D array for the initial position of Mercury, with the x-coordinate being 2.44e6 and the y-coordinate being 0
原文地址: http://www.cveoy.top/t/topic/hAeb 著作权归作者所有。请勿转载和采集!