View the code and add the following: This is also inside the code to show you where it must be added. % 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" %*******************************************************   CODE:   % 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)')

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
icon
Concept explainers
Question

View the code and add the following: This is also inside the code to show you where it must be added.

% 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"
%*******************************************************
 
CODE:
 
% 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 4 steps with 6 images

Blurred answer
Knowledge Booster
Control Structure
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education