我必须根据数据从核心pf土星绘制100e6到1e6重力引起的加速度,并进行计算,但我坚持认为ax和y必须具有相同的第一维,但是形状必须为(61,)和( 1)错误。我真的不知道该怎么做,以及如何将g和土星的内外相加在图的同一条线上。
import numpy as np
from scipy.integrate import quad
from scipy.interpolate import interp1d as i1d
from scipy.constants import G
import matplotlib.pyplot as plt
data_s = np.loadtxt('saturn.txt', delimiter=' ')
radius = np.array(data_s[:,0])
density = np.array(data_s[:,1])
int_f = i1d(radius, density, kind='linear', bounds_error=False, fill_value=0)
Rmax = radius[60]
r = np. linspace(0, 100e6, 10001)
def M(r):
def f(r):
return (4*np.pi) * (int_f(r) * r**2)
sol_s, unc_s = quad(f, 0, 60e6)
def g_out(r):
return (G * M(Rmax)) / r**2
def g_in(r):
return (G * M(r)) / r**2
plt.plot(radius, g_out)