Trajectory plot wont graph...

I'm fairly new to MATLAB and am trying to write a program to test predicted trajectory paths. My goal is to determine the initial velocity needed for a projectile to reach targets spaced 1 foot apart (3-12ft). I wrote a script using kinematic equations rearranged for v0 and but this inside a for loop with the conditions x = 3:1:12. I can't seem to figure out why it isn't graphing. Any help would be appreciated! Code is listed below.
theta = (75); %degrees
a = -32.2; %ft/s^2
vyFinal = 0; %ft
yInitial = 1; %ft
% Set loop to graph in 1 foot increments from 3 to 12 ft
for x = 3:1:12
% Find required initial velocity based off distance (varies per loop)
v0 = sqrt((vyFinal^2)-(2*a*x));
% Determine time of flight
t = (2*v0.*sin(theta*(pi/180)))/a;
% Break v0 into components
vxInitial = v0.*cos(theta*(pi/180));
vyInitial = v0.*sin(theta*(pi/180));
% Create graph of trajectories
x = vxInitial.*t;
y = vyInitial.*t-0.5*a.*t.^2;
plot(x,y);
hold on;
end

Réponses (1)

theta = (75); %degrees
a = -32.2; %ft/s^2
vyFinal = 0; %ft
yInitial = 1; %ft
% Set loop to graph in 1 foot increments from 3 to 12 ft
for x = 3:1:12
% Find required initial velocity based off distance (varies per loop)
v0 = sqrt((vyFinal^2)-(2*a*x));
% Determine time of flight
t = (2*v0.*sin(theta*(pi/180)))/a;
% Break v0 into components
vxInitial = v0.*cos(theta*(pi/180));
vyInitial = v0.*sin(theta*(pi/180));
% Create graph of trajectories
x = vxInitial.*t;
y = vyInitial.*t-0.5*a.*t.^2;
plot(x, y, '-*');
hold on;
end
plot() only ever creates a line of there are at least two adjacent finite coordinates in one call . Every call to plot() creates one or more line objects that are disconnected from all other line objects. When you only ask to plot one coordinate at a time, you will not get any lines.
In order to get lines, you need to record the x and y values, and plot() the entire record of them afterwards. Or you can use animatedline

Catégories

En savoir plus sur 2-D and 3-D Plots dans Centre d'aide et File Exchange

Produits

Version

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by