% 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.   clear clc     vel=input('input the initial velocity in m/sec: '); angle=input('input the angle of launch in degrees: '); % convert the degrees into radians so MATLAB likes it   angle=angle*pi/180;   % set initial position and time 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 velx=vel*cos(angle); VelocityX(1)=velx; vely=vel*sin(angle); VelocityY(1)=vely; % set a time step deltaTime=.001 % seconds height=y(1); while height>=0 % it has not hit ground yet index=index+1; % break velocity into its components velx=vel*cos(angle); vely=vel*sin(angle); % ******************************************************* % 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. Calculated the acceleration % in the y direction inside the if/else statement. % 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)')

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter3: Input/output
Section: Chapter Questions
Problem 4PE: 4. During each summer, John and Jessica grow vegetables in their backyard and buy seeds and...
icon
Related questions
Question
Need help writing the code, the sections where ********************** are on top and bottom are what need to be completed. 
 
 
% 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.
 
clear
clc
 
 
vel=input('input the initial velocity in m/sec: ');
angle=input('input the angle of launch in degrees: ');
% convert the degrees into radians so MATLAB likes it
 
angle=angle*pi/180;
 
% set initial position and time
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
velx=vel*cos(angle);
VelocityX(1)=velx;
vely=vel*sin(angle);
VelocityY(1)=vely;
% set a time step
deltaTime=.001 % seconds
height=y(1);
while height>=0 % it has not hit ground yet
index=index+1;
% break velocity into its components
velx=vel*cos(angle);
vely=vel*sin(angle);
% *******************************************************
% 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. Calculated the acceleration
% in the y direction inside the if/else statement.
% 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)')
 
 
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Mathematical functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr