弹丸运动

时间:2018-11-18 04:17:04

标签: matlab graph matlab-figure projectile

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

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)

这是图形的外观:

expected output

1 个答案:

答案 0 :(得分:1)

在您的代码中,T代表初始学位。您要针对不同的初始度数(x)计算y5:5:85。对T使用for循环,并为不同的x绘制yt

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

enter image description here