Question
Please help me complete the code in Matlab % Create a program to plot the motion of the ping pong ball with drag. % The
Please help me complete the code in Matlab
% Create a program to plot the motion of the ping pong ball with drag.
% The program will take inputs for velocity in m/s and angle of launch.
% note that with a high speed camera I estmated a launch speed for a ping
% pong ball could be 30 m/s.
vel=30; %m/s
angle=60;
% convert the degrees into radians so MATLAB likes it
angle=angle*pi/180;
% set initial values (time, distance, mass, gravity, drag)
x(1)=0; % meters
y(1)=.01; % meters
time(1)=0; % seconds
mass=.00247; %kg ping pong ball .00247 Kg
g=-9.8; % m/sec^2
c=-0.0005; % coefficient of drag with density and area in this constant
index=1; % so I can load an array for plotting
% start to increment the motion and define it component forces
velx=vel*cos(angle);
VelocityX(1)=velx;
vely=vel*sin(angle);
VelocityY(1)=vely;
% set a time step and variable for height
deltaTime=.001; % seconds
height=y(1);
while height>=0 % check that the ball has not hit ground yet
index=index+1; % setup and index
% *******************************************************
% break velocity into its components
% *******************************************************
% *******************************************************
% use an if/else statement to check to see if the ball is moving
% down (negative). If it is, then drag has an opposite sign
% as gravity in the acceleration formula. Otherwise gravity
% and drag have the same sign. Calculate the new acceleration in the y.
% *******************************************************
% *******************************************************
% Now calculate the acceleration in the x .
% *******************************************************
% *****************************************************
% calculate the new velocity at the end of the time step
% this will have X and Y components, so you need a variable
% for each. One is velFinalX and the other is velFinalY.
% *******************************************************
% ******************************************************
% Get a new velocity vector and angle given the X and Y
% The velocity is the variable "vel" and angle is "angle"
%*******************************************************
% now save my values at this time step
time(index)=time(index-1)+deltaTime;
VelocityX(index)=velFinalX;
VelocityY(index)=velFinalY;
% and distance numbers
distX=velx*deltaTime;
distY=vely*deltaTime;
% save distance values
x(index)=x(index-1)+distX;
y(index)=y(index-1)+distY;
height=y(index);
end
plot(x,y)
title('distance traveled by ping pong ball in meters')
xlabel('horixontal distance traveled (meters)')
ylabel('vertical distance traveled (meters)')
it is a model of motion under drag force, help me make it create values to place into arrays to plot on a graph as shown in the picture, I dont understand the equations I am supposed to use
Your Task: Copy the code into Matlab to open and review it. Here are the parts: Initialize Variables - Use the comments to figure out what these are. Student developed code - A section for you to imput code that uses a while loop to calculate the motion of the ping pong ball. The spaces that need code are called out with %** ***** and a hint inside about what is missing. Note the variable names suggested in these hints so that the rest of the code will work once those things are added. Plotting of final values - This plot should look like the following. distance traveled by ping pong ball in meters vertical distance traveled (meters) 12 6 8 10 horixontal distance traveled (meters)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started