模拟太空引擎

问题描述 投票:0回答:1

我想在模拟初始推力的初始条件下从低地球轨道模拟太空发动机的运动。

我做了所有的代码,但是当我绘制 ODE 解决方案时,我只有一个点,我只是不知道我错在哪里。

我把代码放在这里,不是很复杂,我只需要求解运动方程即可。

function sol = orbital_motion()
% Define the function that returns the derivative of the state vector
    function dydt = ode(t, y)
        % Extract the state variables
        X = y(1);
        Y = y(2);
        Z = y(3);
        Xdot = y(4);
        Ydot = y(5);
        Zdot = y(6);
     
        Xm = 278,481; Ym = 378,481; Zm = 268,481;
        Xs = 147098,074 ; Ys = 696,166 ; Zs = 1515,776 ;
        mu_e = 3.986135e14; %sets the gravitational parameter for the Earth.
        mu_m = 4.89820e12;%sets the gravitational parameter for the Moon.
        mu_s = 1.3253e20;%sets the gravitational parameter for the Sun.
        a = 6.37826e6; %the equatorial radius of the Earth.
        J = 1.6246e-3;%sets the Earth's second dynamic form factor.
        % Calculate the distances and other parameters
        r = sqrt(X^2 + Y^2 + Z^2);
        rm = sqrt(Xm^2 + Ym^2 + Zm^2);
        delta_m = sqrt((X - Xm)^2 + (Y - Ym)^2 + (Z - Zm)^2);
        delta_s = sqrt((X - Xs)^2 + (Y - Ys)^2 + (Z - Zs)^2);
        Y_s = Ys;
        Z_s = Zs;
        % Calculate the derivatives
        X2dot = -((mu_e*Y)/r^3) * (1 + (J*(a/r)^2)*(1 - 5*Z^2/r^2)) ...
            - (mu_m*(X - Xm)/delta_m^3) ...
            - (mu_m*Xm/rm^3) ...
            - (mu_s*(X - Xs)/delta_s^3) ...
            - (mu_s*Xs/r^3);
        Y2dot = -((mu_e*Y)/r^3) * (1 + (J*(a/r)^2)*(1 - 5*Z^2/r^2)) ...
            - (mu_m*(Y - Ym)/delta_m^3) ...
            - (mu_m*Ym/rm^3) ...
            - (mu_s*(Y - Y_s)/delta_s^3) ...
            - (mu_s*Ys/r^3);
        Z2dot = -((mu_e*Z)/r^3) * (1 + (J*(a/r)^2)*(3 - 5*Z^2/r^2)) ...
            - (mu_m*(Z - Zm)/delta_m^3) ...
            - (mu_m*Zm/rm^3) ...
            - (mu_s*(Z - Z_s)/delta_s^3) ...
            - (mu_s*Zs/r^3);
     
        % Return the derivative vector
        dydt = [Xdot; Ydot; Zdot; X2dot; Y2dot; Z2dot];
    end

% Set the initial conditions
X0 = 0;
Y0 = 0;
Z0 = 0;
Xdot0 = 11436.6;
Ydot0 = 0;
Zdot0 = 0;
y0 = [X0; Y0; Z0; Xdot0; Ydot0; Zdot0];

% Define the time span
tf = 20;
tspan = [0, tf];

% Call ODE45
%options = odeset('RelTol', 1e-8, 'AbsTol
# [t,y] = ode45(@ode,[0 20],y0);
plot(t,y(:,1),'-o',t,y(:,2),'-o',t,y(:,3),'-o')
title('Solution of the Motion Equation with gODE45');
end**your text**
matlab ode
1个回答
0
投票

不要在数字常量中使用逗号:

Xm = 278,481; Ym = 378,481; Zm = 268,481;
Xs = 147098,074 ; Ys = 696,166 ; Zs = 1515,776 ;

如果他们应该是小数点,使用句点:

Xm = 278.481; Ym = 378.481; Zm = 268.481;
Xs = 147098.074 ; Ys = 696.166 ; Zs = 1515.776 ;

否则,只需消除它们:

Xm = 278481; Ym = 378481; Zm = 268481;
Xs = 147098074 ; Ys = 696166 ; Zs = 1515776 ;
© www.soinside.com 2019 - 2024. All rights reserved.