We are creation a MATLab simulation of a projectile motion equation of a ping pong ball being launched by a slingshot. I have completely figured out how my script needs to be written, but each time I run it it's giving me weird answers. Please Help!!

7 views (last 30 days)
%% Horz Travel Dist (RB1)
clc;clear;
d = (.125:.125:4); %Distance matrix
d = d*.0254; %coverting inches to meters (m)
angle = input('What Angle is of Interest? ');
angle = angle*pi/180; % Converts Degrees to Radians
k = (.5292); % Spring Constant (F)
m = .0027; % Mass of the ball (kg)
g = 9.80665; %acceleration due to gravity (m/s^2)
A = (k*d)/m; %non-linear spring acceleration (m/s^2)
Voy = sqrt((2*d*sin(angle)).*(A*sin(angle)-g)); %Y Initial Velocity
Vox = cos(angle)*sqrt(2*d.*A); %X Initial Velocity
n = 1;
while (n <= 32) % Loop that computes the time for the ball to travel
a =-4.903325;
b = Voy(n);
c = 0;
e = [a, b, c];
T(:,n) = roots(e);
t(n) = max(T(:,n));
n = n+1;
end
n = 1;
while (n <= 32) % Loop computes the Distance traveled by the ball
x(n) = Vox(n)*t(n)*cos(angle);
n = n+1;
end
disp(x/.3048) % Converts meters to feet

Answers (0)

Categories

Find more on Gravitation, Cosmology & Astrophysics 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!