How to; For loop of angle in projectile motion
15 views (last 30 days)
Show older comments
Im trying to get a for loop to run a projectile motion from an angle pi/6 to pi/3 and then run a function that finds the range for each and returns the maximum one (would be at 45 degrees), so far I believe I have the for loop run through the angles correctly but when the range function runs it does not display the corresponding range values, it only returns the value for pi/6, for the increment number of times:
g = 9.82; %gravity
v0 = 100; %inital velocity
theta0 = pi/6;
T = (2*v0*sin(theta0))/g; % Theoretical flight time
t = linspace(0,T,1001);
[r,v] = Projectile(t,v0,theta0); %link to projectile function
figure(1), plot(r(:,1),r(:,2));
xlabel('Distance (m)');
ylabel('Height (m)');
legend('Trajectory path');
R = FindRange(r); %link to find range function
disp("Range = " + (R) + "m");
m = max(r(:,2));%Max height
disp("Maximum Height = " + (m) + "m");
disp("Flight time = " + (T) + "sec");
for theta0 = pi/6:pi/180:pi/3
R1 = FindRange(r);
disp (R1)
end
0 Comments
Answers (2)
KSSV
on 20 Aug 2022
You are not updating the theta0 to find the range. You need to input theta0 to the function.
clc; clear all ;
g = 9.82; %gravity
v0 = 100; %inital velocity
theta0 = pi/6;
T = (2*v0*sin(theta0))/g; % Theoretical flight time
t = linspace(0,T,1001);
[r,v] = Projectile(t,v0,theta0); %link to projectile function
figure(1), plot(r(:,1),r(:,2));
xlabel('Distance (m)');
ylabel('Height (m)');
legend('Trajectory path');
R = FindRange(r); %link to find range function
disp("Range = " + (R) + "m");
m = max(r(:,2));%Max height
disp("Maximum Height = " + (m) + "m");
disp("Flight time = " + (T) + "sec");
for theta0 = pi/6:pi/180:pi/3
T = (2*v0*sin(theta0))/g; % Theoretical flight time
t = linspace(0,T,1001);
[r,v] = Projectile(t,v0,theta0); %link to projectile function
R1 = FindRange(r);
disp (R1)
end
Sam Chak
on 20 Aug 2022
Hi @Aston
g = 9.82; % gravity
v0 = 100; % inital velocity
theta0 = pi/6;
T = (2*v0*sin(theta0))/g; % Theoretical flight time
t = linspace(0,T,1001);
[r, v] = Projectile(t,v0,theta0); % link to projectile function
figure(1),
plot(r(:,1), r(:,2));
xlabel('Distance (m)');
ylabel('Height (m)');
legend('Trajectory path');
R = FindRange(r); %link to find range function
disp("Range = " + (R) + "m");
m = max(r(:,2));%Max height
disp("Maximum Height = " + (m) + "m");
disp("Flight time = " + (T) + "sec");
Suggest the for loop in this structure:
% Range of initial angle
theta0 = pi/6:pi/180:pi/3
for j = 1:length(theta0)
% Call function that uses theta0(j)
end
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!