g = -9.8;
xi = 0;
yi = 5;
vMAX = sqrt(-yi.*g*2);
fprintf('Angle(d)\t V(m/s)\t height(m)\t Range(m)\n');
for theta2=10:10:90
for vi =linspace(0,vMAX,10);
vix = vi.*cosd(theta2);
viy = vi.*sind(theta2);
a = (1/2)*g;
b = viy;
c = yi;
tFinal2 = roots([a, b, c]);
tFinal2 = max(tFinal2);
t = (linspace(0, tFinal2, 10))';
x2 = xi+vix.*t;
y2 = yi+viy.*t+(1/2)*g.*t.^2;
R = Range2(xi,vix,tFinal2);
yMAX = MaxHeight2(viy);
end
fprintf("%.2f \t\t %.2f\t\t %.2f\t\t %.2f\n",theta2,vi,yMAX,R)
subplot(3,2,4)
plot(x2, y2,'LineWidth',1.5);
hold on
grid on;
xlabel('X');
ylabel('Y');
title ('Projectile with varying angle & initial velocity (h)')
axis equal;
y2(y2 < 0) = 0;
end
2 件のコメント
darova (view profile)
このコメントへの直接リンク
https://jp.mathworks.com/matlabcentral/answers/488880-for-loops-for-2-variables-trajectory#comment_762925
Ahmed M'sallem (view profile)
このコメントへの直接リンク
https://jp.mathworks.com/matlabcentral/answers/488880-for-loops-for-2-variables-trajectory#comment_762927
サインイン to comment.