How do I write a projectile motion code that is automated and plots motion given certain heights, angles and initial velocity?
Show older comments
I need help writing a "for" or "while" code that is automated in a sense where it plots the projectile's motion given the heights, angles and initial velocity. I am not including drag or rolling after the initial launch since I want to learn the basics.
2 Comments
James Tursa
on 2 Feb 2022
What have you done so far? What specific problems are you having with your code?
Paul Jones
on 2 Feb 2022
Accepted Answer
More Answers (1)
David Hill
on 2 Feb 2022
function d = projMotion(velocity,height,angle)
Vyi=velocity*sind(angle);
g=9.81;
tmax=(2*Vyi/g+sqrt((2*Vyi/g)^2+8*height/g))/2;
t=0:.001:tmax;
d=height+Vyi*t-.5*g*t.^2;
plot(t,d)
end
4 Comments
Paul Jones
on 3 Feb 2022
David Hill
on 3 Feb 2022
velocity=16;
figure;
hold on;
for height=1:2
for angle=30:15:60
d=projMotion(velocity,height,angle);
end
end
Paul Jones
on 3 Feb 2022
Edward
on 15 Feb 2023
Any chance you can explain where you got the tmax from? Im struggling to recreate it and dont know why its 8*height/g
Thanks!
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

