How can I add an initial position above x-axis in my projectile motion function?
Show older comments
I want some help in my Projectile motion function where i can launch my projectile from a platform above x-axis and Still hit the ground Thanks in advance.
function [range,maxh,xmaxh]= projectilemotion1(x0,y0,v0,angle,g)
% inputs
% x0 = Initial x value (starting distance)
% y0 = Initial y value (starting height)
% v0 = Initial velocity
% angle = angle of projectile
% g=gravitational acceleration
% outputs
% range = maximum distance
% maxh = max height
% xmaxh = x co-ordinate at the highest point
range = (v0.^2)./g * sind(2*angle);
xstep = range ./150;
x = x0:xstep:range;
y = (x*tand(angle) - g /(2*(v0.^2)*(cosd(angle)).^2)*x.^2)+y0;
for i=1:length(x)
h=plot(x(i),y(i),'.');
set(h,'LineWidth',2);
xlabel('Distance (Meters)');
ylabel('Height (Meters)');
hold on
pause(0.001);
end
zoom on;
maxh = max(y)
xmaxh = (v0.^2)./(2*g)*sind(2*angle)
Time = sqrt(2*maxh)./g
h=plot(xmaxh,maxh,'g.');
set(h,'MarkerSize',20);
end
2 Comments
KSSV
on 25 Apr 2017
Copy the code instead of a snapshot image, so that people can help you.
Sherif Rafik
on 25 Apr 2017
Accepted Answer
More Answers (0)
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!