% 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)')
% 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...
Related questions
Concept explainers
Max Function
Statistical function is of many categories. One of them is a MAX function. The MAX function returns the largest value from the list of arguments passed to it. MAX function always ignores the empty cells when performing the calculation.
Power Function
A power function is a type of single-term function. Its definition states that it is a variable containing a base value raised to a constant value acting as an exponent. This variable may also have a coefficient. For instance, the area of a circle can be given as:
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
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
Knowledge Booster
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.Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr