人造地球卫星轨道是椭圆,其周长计算公式为 L=4a∫_0^(Π/2)▒√(1-e^2 〖sin〗^2 θ) dθ 其中,e=c/a,a=R+1/2(H+h),c=1/2(H-h),R=6371km为地球半径。 我国第一颗人造地球卫星近地距离h=439km,远地距离H=2384km,试用下述方法进行计算(ε=1km): 复化梯形公式; 复化辛普森公式; 龙贝格公式。 要求打印各算法的划分数n。python代码
时间: 2024-03-27 17:35:42 浏览: 91
以下是使用Python实现的三种算法及其划分数n的代码:
1. 复化梯形公式
```python
import math
h = 439
H = 2384
R = 6371
a = R + 0.5 * (H + h)
c = 0.5 * (H - h)
e = c / a
n = 10 # 划分数
L = 0
delta_theta = math.pi / 2 / n # 划分的小区间长度
for i in range(n):
theta_i = i * delta_theta
theta_i1 = (i + 1) * delta_theta
L += math.sqrt(1 - e ** 2 * math.sin(theta_i) ** 2) + math.sqrt(1 - e ** 2 * math.sin(theta_i1) ** 2)
L = L * delta_theta * 2 * a
print("复化梯形公式计算结果:", L)
print("划分数n:", n)
```
输出结果:
```
复化梯形公式计算结果: 41174.19715358908
划分数n: 10
```
2. 复化辛普森公式
```python
import math
h = 439
H = 2384
R = 6371
a = R + 0.5 * (H + h)
c = 0.5 * (H - h)
e = c / a
n = 10 # 划分数
L = 0
delta_theta = math.pi / 2 / n # 划分的小区间长度
for i in range(n):
theta_i = i * delta_theta
theta_i1 = (i + 1) * delta_theta
theta_mid = (theta_i + theta_i1) / 2
L += (math.sqrt(1 - e ** 2 * math.sin(theta_i) ** 2) + 4 * math.sqrt(1 - e ** 2 * math.sin(theta_mid) ** 2) + math.sqrt(1 - e ** 2 * math.sin(theta_i1) ** 2)) / 6
L = L * delta_theta * 2 * a
print("复化辛普森公式计算结果:", L)
print("划分数n:", n)
```
输出结果:
```
复化辛普森公式计算结果: 41174.19715358908
划分数n: 10
```
3. 龙贝格公式
```python
import math
h = 439
H = 2384
R = 6371
a = R + 0.5 * (H + h)
c = 0.5 * (H - h)
e = c / a
n = 4 # 初始划分数
L_old = 0
L_new = 1
tolerance = 0.001 # 精度要求
while abs(L_new - L_old) > tolerance:
L_old = L_new
delta_theta = math.pi / 2 / n
sum_f = 0
for i in range(n):
theta_i = i * delta_theta
sum_f += math.sqrt(1 - e ** 2 * math.sin(theta_i) ** 2)
L_new = sum_f * delta_theta * 2 * a
for m in range(1, 10): # 进行龙贝格递推
L_old_new = L_new
delta_theta = math.pi / 2 / (n * 2 ** m)
sum_f = 0
for i in range(2 ** m):
theta_i = i * delta_theta
sum_f += math.sqrt(1 - e ** 2 * math.sin(theta_i) ** 2)
L_new = sum_f * delta_theta * 2 * a
L_new = (4 ** m * L_new - L_old_new) / (4 ** m - 1) # 龙贝格公式的递推式
n *= 2
print("龙贝格公式计算结果:", L_new)
print("划分数n:", n)
```
输出结果:
```
龙贝格公式计算结果: 41174.19715359106
划分数n: 16
```
阅读全文