Calculating time component on a function

조회 수: 1 (최근 30일)
Ryan Bowman
Ryan Bowman 2018년 12월 9일
답변: Stephan 2018년 12월 9일
I have a function and I run it through a for loop a certain amount of times and every time I go through an iteration I want to compute the amount of time it takes for the trajecotry to hit the ground from when it is shot out of a cannon. For each theta it should spit out an endtime for that specified amount of time. Any help on how to do that?? Here is my function I am using.
function [x_p,y_p] = BowmanHW3_ProjectileEqn(v0,theta,t,a)
x_p = v0.*cosd(theta).*t; %m
y_p = v0.*sind(theta).*t+(0.5*a.*(t.^2));%m
And here is my main script:
%% Problem 1
v0 = 460; %m/s
a = -9.81; %m/s^2
t = (0:0.1:300); %time(s)
for theta = 5:10:85 %Initial and final firing angle with 10 degree increments
[x_p,y_p] = BowmanHW3_ProjectileEqn(v0,theta,t,a);
figure(1), hold on
plot (x_p,y_p)
xlim([0 22000]);
ylim([0 11000]);
xlabel('X Position (m)')
ylabel('Y Position (m)')
title('Projectile Trajectory')
endtime = BowmanHW3_ProjectileEqn(v0,theta,t,a)
end
legend('5 Degrees','15 Degrees','25 Degrees','35 Degrees','45 Degrees','55 Degrees','65 Degrees','75 Degrees','85 Degrees')

채택된 답변

Stephan
Stephan 2018년 12월 9일
Hi,
have a look to this accepted answer to solve your problem - the question is very similar to yours.
Best regards
Stephan

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by