# Plotting a projectile (it doesn't plot anything)

3 views (last 30 days)
Obed James on 7 May 2021
Commented: Obed James on 7 May 2021
disp (['not part of anything but i wrote this below and no matter what i do ' ...
' n/ i cant get it to plot, Please help me ' ...
'n/My original plan was to get it to plot in an animated ' ...
' n/format but id take anything if it works'])
close all %Closes all other windows associated with Matlab.
clear %Erases all existing variables.
clc %Clears the command window.
%% Input Data
disp ('What are the given Data')
prompt = 'What is the Initial Speed of the projectile in m/s?';
v0 = input (prompt);
prompt2 = 'What is the angle of the projectile in degrees?';
theta = input (prompt2);
prompt3 = 'What is the acceleration due to gravity in m/s^2?';
g = input (prompt3);
%%Calculations and those other sections can be used to display the calculated data
%% TODO
disp ('Given Data')
v = 0;
%% The horizontal component of the velocity.
disp ('Horizontal Velocity (HV)')
HV = v0*cosd(theta);
%% The vertical component of the velocity.
disp ('Vertical Velocity (VV)')
VV = v0*sind(theta);
%% The greatest height above ground attained by the shell.
disp ('Greatest height above ground in meters')
Vsy = abs((v^2 -(VV^2))/(2*g)); % abs() is used to make the value always postive.
%% Time Taken for the projectile to fall to the ground after reaching it's maximum height.
disp ('Time Taken in seconds (tt)')
tt = abs((v-VV)/g);
%% Total air time of the projectile.
disp ('Total Time (Tt)')
TT = tt*2;
T = linspace(0,TT);
%% Maximum Horivontal distance travelled by the projectile
disp ('Max Horizontal Distance')
Hsx = HV*T;
%% Pjectiles motion shown graphically
plot(Hsx, Vsy, 'b-', 'LineWidth', 3);
grid on;
grid minor

Chunru on 7 May 2021
Try this:
disp (['not part of anything but i wrote this below and no matter what i do ' ...
' n/ i cant get it to plot, Please help me ' ...
'n/My original plan was to get it to plot in an animated ' ...
' n/format but id take anything if it works'])
close all %Closes all other windows associated with Matlab.
clear %Erases all existing variables.
clc %Clears the command window.
%% Input Data
disp ('What are the given Data')
prompt = 'What is the Initial Speed of the projectile in m/s? ';
v0 = input (prompt);
prompt2 = 'What is the angle of the projectile in degrees? ';
theta = input (prompt2);
prompt3 = 'What is the acceleration due to gravity in m/s^2? ';
g = input (prompt3);
%%Calculations and those other sections can be used to display the calculated data
%% TODO
disp ('Given Data')
v = 0;
%% The horizontal component of the velocity.
HV = v0*cosd(theta);
fprintf('Horizontal Velocity (HV): %f\n', HV)
%% The vertical component of the velocity.
VV = v0*sind(theta);
fprintf ('Vertical Velocity (VV): %f\n', VV)
%% The greatest height above ground attained by the shell.
Vsy = abs((v^2 -(VV^2))/(2*g)); % abs() is used to make the value always postive.
fprintf ('Greatest height above ground in meters: %f\n', Vsy)
%% Time Taken for the projectile to fall to the ground after reaching it's maximum height.
tt = abs((v-VV)/g);
fprintf('Time Taken in seconds (tt): %f\n', tt)
%% Total air time of the projectile.
TT = tt*2;
fprintf ('Total Time (Tt): %f \n', TT)
T = linspace(0,TT,50); % 50 points
%% Maximum Horivontal distance travelled by the projectile
Hsx = HV*T;
fprintf ('Max Horizontal Distance: %f \n', Hsx(end))
%% Pjectiles motion shown graphically
% Hsx is the horizontal distance points
Hsy = VV*T - 0.5*g*T.^2;
plot(Hsx, Hsy, 'b-', 'LineWidth', 3);
grid on;
grid minor
Make sure compute the value before display (or fprintf).
##### 1 CommentShowHide None
Obed James on 7 May 2021
Thank you so much. I'm not entirely sure what u did but i'm seeing the linspace is different and thx for the tip on fprintf

### More Answers (1)

VBBV on 7 May 2021
%if true
plot(Hsx, 'b-', 'LineWidth', 3);
grid on;
grid minor
Vsy is scalar with one value. That's why plot does not show. If you want to plot, make it a vector.
##### 1 CommentShowHide None
Obed James on 7 May 2021
I'm gonna have to learn about that asap.