How do I plot the trajectory?
Show older comments
I'm not sure why it woudn't plot.
clc;clear
%Before Impact
%Horizontal direction
Sx=2.8; %the distance before impact
So=0; %the initial distance
V=10; %velocity it threw
Vx=V*cosd(20) %velocity in x direction
Voy=V*sind(20) %velocity in y direction
a=9.81; %acceleration of gravity
Soy=1.3;
e=.88; %coefficienet of restitution
t=(Sx+So)/Vx
% Vertical Direction
Vy=Voy-a*t %velcoity before impact
%During Impact
%The point where the ball will hit the wall vertically
Sy=Soy+Voy*t-.5*a*t^2
%Magnitude of the velocity
Vb1=sqrt(Vx.^2+Vy.^2) %velocity when it hit the wall
Theta=atand(Vy/Vx) % the angle it went
%Conservation of Momentum in Y_direction
Vb2sinbeta=Vy
Vb2cosbeta=e*Vx
Beta=atand(Vb2sinbeta/Vb2cosbeta)
%Velocty at with the ball bounce back from the wall
Vb2= Vb2cosbeta/(cosd(Beta))
% After the Impact
a=.5*a
b=-Vb2*(sind(Beta))
c=-Sy
x1=(-b+sqrt(b.^2-4.*a.*c))/(2.*a)
x2=(-b-sqrt(b.^2-4.*a.*c))/(2.*a)
if (x1 >=0)
S= So+Vb2*cosd(Beta)*x1
else
S= So+Vb2*cosd(Beta)*x2
end
%plot of the trajectory
x= Sx+Vb2*cosd(Beta)*x1
y=Soy+Vy*t+.5*a*t.^2
plot(x,y)
hold on
xx=(0:.88:5.56)
y1=S
plot(xx,y1,xlim,[0,0])
xlabel('Horizontal Distance')
ylabel('velocity the ball travelling')
2 Comments
Image Analyst
on 29 Jun 2020
When you do this to reassign x with a new x:
x= Sx+Vb2*cosd(Beta)*x
what is the original x when you get to that point? It's saying it's undefined.
abraj ali
on 29 Jun 2020
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!