Question: Modify the following code. Suppose the projectile is a bouncy ball. The launch velocity decreases by 20 percent after each bounce, such that the launch
Modify the following code. Suppose the projectile is a bouncy ball. The launch velocity decreases by 20 percent after each bounce, such that the launch velocity of the current bounce = 0.8 * launch velocity of the previous bounce. Show a movie of at least 3 bounces with the movie auto-scaled to show the entire path.
% This program displays a movie of a projectile, given a starting velocity and launch angle
% This is a revised version of the MATLAB code for animation of projectile motion
% on page 70 of Applied Numerical Methods With MATLAB, Third edition, Steven Chapra.
% Program name: ProjectileMovie.m
clc; % clear workspace screen
close all;% close all figures
clear; % clear all variables
% Parameters
g=9.81; % acceleration due to gravity
% INPUT
Degrees=input('Enter launch angle in degrees in the range 0 to 90 degrees: '); % launch angle in degrees from user
if (Degrees<0 || degrees>90) % checking the velocity if it is not in given range enter to if block
fprintf('Your Input is not valid..! '); %hint to user that the entered value is not in given range
Degrees=input('please Enter launch angle in degrees in the range 0 to 90 degrees: '); %again ask the value
end
% ANGLE
theta0=Degrees*pi/180; % launch angle in radians
% Ask user for launch velocity
v0=input('Enter launch velocity in meters per second should not be less than or equal to zero: '); % initial launch velocity (meters/second)
if (v0<=0) % checking the velocity if it is less than or equal to 0 enter to if block
fprintf('Your Input is not valid..! '); %hint to user that the entered value is less than or equal to 0
Degrees=input('please Enter launch velocity in meters per second should not be less than or equal to zero: '); %again ask the value
end
t(1)=0;x=0;y=0; % start time and starting position
% Equation Identification
v_y0=v0*sin(theta0); %formula for initial vertical velocity
v_x0=v0*cos(theta0); %formula for initial horizontal velocity
M_H=(v_y0^2)/(2*g); % calculate maximum height
T_impact=(2*v_y0)/(g); %time to impact in seconds
M_L=v_x0*T_impact; % calculate maximum distance
% Display a marker at the starting position
figure
plot(x,y,'o','MarkerFaceColor','b','MarkerSize',8) % place a circle marker at the starting position
axis([0 M_L+1 0 M_H+1]) %scale xmin xmax ymin ymax.
M(1)=getframe; % save the current figure to the first movie frame
% Display markers along the path of the projectile
dt=1/128; % step time in seconds
i = 2; % counter to represent the movie frame number
while (y>=0)
t(i)=t(i-1)+dt; % step to the next time sample
x=v0*cos(theta0)*t(i); % calculate the horizontal position
y=v0*sin(theta0)*t(i)-0.5*g*t(i)^2; % calculate the vertical position
plot(x,y,'o','MarkerFaceColor','b','MarkerSize',8)% place a circle markers at the current position
ylabel('height in meters')
xlabel('distance in meters')
grid
% scale
axis([0 M_L+1 0 M_H+1]) % adjusted axis to maximum length and maximum height
M(i)=getframe; % save the current figure to the next movie frame
i = i + 1; % increment the frame number
end % exit the loop when the height (y) is less than zero
% frames per second
fps = 150; movie(M,1, fps) % play a movie at the set frame rate
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
