使用 matlab 的弹丸运动

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

射弹以 $heta$ 的初始角度和 $V_0$ 的初始速度发射。我想使用计时步长为 0.25 的 while 循环找到最大高度和射弹达到最大高度的时间。

这是我的类比:将使用 $y(t) = -0.5 gt^2 + V_0 \sin heta .t$ 找到的每次高度与之前的值进行比较,如果开始下降,那么我将停止循环。正如您在代码中看到的那样:

V_0 = input("Enter initial velocity: ");
Theta = input("Enter theta: ");
[Height_Max, time] = maxi_heighti (Theta, V_0)

function [Height_Max, time] = maxi_heighti (Theta, V_0)
    g = 9.8;
    v = V_0;
    syms y(t)
    y(t) = -0.5.*g.*t^2 + V_0.*t.*sin(Theta);
    t = 0;
    h_max = y(t);
    while  true
        t = t + 0.25;
        if double(y(t)) < h_max
            break
        end
        h_max = y(t);
    end
    time = t;
    Height_Max = y;
end

但这似乎是错误的。我刚刚学习 MATLAB,如果你能帮助我调试它,我将不胜感激。

matlab
© www.soinside.com 2019 - 2024. All rights reserved.