弹丸运动

Projectile motion

我应该编写一个脚本来提供多行射弹运动,但我的代码似乎没有提供我需要的东西。

disp('This program will calculate the trajectory of a ball thrown at an initial speed vo \n')
v0 = input('Please enter the initial speed');
x0 = 0;
y0 = 0;
g = 9.81;%m/s^2
T = 5 : 5 : 85;
vx = v0*cosd(T);
vy = v0*sind(T);
t = (2*v0.*sind(T))/g;
y = y0 + (vy.*t) - ((g.*(t.^2))/2);
x = x0 + vx.*t;
plot(x,y)

图表应该是这样的:

在你的代码中,T表示初始度数。您想要针对不同的初始度数 (5:5:85) 计算 xy。为 T 使用 for 循环,为不同的 t.

绘制 xy
disp('This program will calculate the trajectory of a ball thrown at an initial speed vo \n')
v0 = input('Please enter the initial speed');
x0 = 0;
y0 = 0;
g = 9.81;%m/s^2
for T = 5 : 5 : 85
    vx = v0*cosd(T);
    vy = v0*sind(T);
    t = linspace(0,(2*v0.*sind(T))/g,100);
    y = y0 + (vy.*t) - ((g.*(t.^2))/2);
    x = x0 + vx.*t;
    plot(x,y)
    hold on
    xlim([-inf inf])
    ylim([-inf inf])
end

输出:

This program will calculate the trajectory of a ball thrown at an initial speed vo \n
Please enter the initial speed10