Projectile motion of a cannonball(without drag) - calculating the route, range, height and time it will spend in the air of a cannonball fired with a certain force
13 次查看(过去 30 天)
显示 更早的评论
A force of 1000 newtons is applied to the cannonball. But the code does not simulate correctly. I could not find my fault. I would be very grateful if you could help. Thanks.
clear;
clc;
g=9.81;
m=1;
F=1000;
dt=0.1;
t=0;
angle=45;
Fx=cosd(angle)*F;
Fy=sind(angle)*F;
axold=Fx/m;
ayold=Fy/m;
vx=0;
vy=0;
x=0;
y=0;
while min(y)>-0.001
t=t+dt;
ax=0;
ay=-g;
if (t==0.1)
vx=vx+dt*(axold)/2;
else
vx=vx+dt*(ax)/2;
end
if (t==0.1)
vy=vy+dt*(ayold)/2;
else
vy=vy+dt*(ay+ayold)/2;
end
if (t==0.1)
x=x+vx*dt+dt*dt*(axold)/2;
else
x=x+vx*dt+dt*dt*(ax+axold)/2;
end
if (t==0.1)
y=y+vy*dt+dt*dt*(ayold)/2;
else
y=y+vy*dt+dt*dt*(ay+ayold)/2;
end
Height=max(y);
end
plot(x,y)
xlabel('x distance (m)')
ylabel('y distance (m)')
title('Cannonball Path')
1 个评论
Image Analyst
2021-5-9
@TOLGAHAN VARISLI, deleting questions after they've been answered is very much frowned upon and may limit the number of answers you get in future questions.
回答(1 个)
Image Analyst
2021-5-8
See my attached projectile demo. It has variables for just about everything you could want to specify and computes just about everything you can possibly think of.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!