你能用可变常数解常微分方程吗?

2024-04-25 13:39:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个统一的任务,我必须建立月球下降模型。模型从一个高度开始下降,两个引擎放置在一个角度下。 这是代码中我有问题的部分:

F1 = f*np.array([1, 1, 0.5, 0, 0, 1, 1]) #f-thrust in newtons
F2 = f*np.array([1, 1, 0.5, 0, 0, 1, 1]) #F1 and F2 regime of engines for each time step(percentage of thrust)

t = np.arange(0, np.size(F1), dt) #time domain

#a,b - angles of engines according to global coordinate system
#s0x, v0x, s0y, v0y, fi0, omg0 - initial values
#m - mass
def model_engine(u, t):
    x, vx, y, vy, phi, w = u   
    d1 = vx
    d2 = (1/(m))*(F1*np.cos((a)) - F2*np.cos((b)))
    d3 = vy
    d4 = (1/(m))*(F1*np.sin((a)) + F2*np.sin((b))) + g 
    d5 = w
    d6 = (F1*np.cos(a)*(h/2) - F1*np.sin(a)*(w/2) + F2*np.sin(b)*(w/2) - 
             F2*np.cos(b)*(h/2))/((1/12)*(m)*h**2)
    return np.array([d1, d2, d3, d4, d5, d6])

U = odeint(model_engine, [s0x, v0x, s0y, v0y, fi0, omg0], t)
  1. 我不知道如何在定义中为每个时间步实现不同的F1?我得到ValueError: setting an array element with a sequence. 变质量也是一样,这取决于发动机的工作状态。

  2. 这个解给出了航天器的角度(d6)。用这种方法写的方程总是给出a和b为45度,这显然是不正确的,因为航天器是旋转的。如何从上一步得到解(角度)并将其放入当前步骤?有关说明,请参见照片

photo


Tags: of模型timenpsincosarrayf2
1条回答
网友
1楼 · 发布于 2024-04-25 13:39:24

第一个问题的方法是:如何实现可变系数?推力被假定为仅为t的阶跃函数。它是通过在相应的时间对给定的推力指令进行插值得到的。插值函数作为附加参数传递给model_engine函数。你知道吗

该模型简化为具有恒定质量的垂直着陆器。你知道吗

import matplotlib.pylab as plt

import numpy as np
from scipy.interpolate import interp1d
from scipy.integrate import odeint

from scipy.constants import g

def model_engine(u, t, thrust, mass):
    y, vy = u 

    dydt = vy
    dvy_dt = 1/mass * thrust(t) - g 

    return np.array([dydt, dvy_dt])


# Thrust definition:
F_values = g*np.array([1, 1, 0.5, 0, 0, 2, 2, 1.5, 1]) # f-thrust in newtons
timesteps = np.linspace(0, 10, np.size(F_values)) # timesteps used to defined the thrust

thrust = interp1d(timesteps, F_values, kind='previous', fill_value='extrapolate')

# Solve
s0y, v0y = 102, 0
m0 = 1
t_span = np.linspace(0, 1.2*timesteps[-1], 111)
U = odeint(model_engine, [s0y, v0y], t_span, args=(thrust, m0))

# Graphs
plt.figure();
plt.plot(t_span, U[:, 0], label='altitude')
plt.axhline(y=0, color='black', label='moon surface');
plt.xlabel('time'); plt.legend();

plt.figure();
plt.plot(t_span, thrust(t_span), label='thrust');
plt.xlabel('time'); plt.legend();

相关问题 更多 >