From: William on
Hi, Im trying to figure out a way to display a "range" for the given function below. However, the number I would like to display as the "range" of this function should only be the last positive value along the x axis. Any insight is apperciated.



% trajectory: function to solve trajectory motion with inputs of angle
% velocity, and position.
%
% y = trajectory_motion(angle,V,p)
%
% angle = Angle of trajectory
% V = Velocity
% p = Position from x-axis.
%
% Inputs

close all; clear all; clc;

angle = input('Enter angle of trajectory (degrees)= '); %Angle
V= input('Enter velocity= '); %Velocity
p= input('Enter Position of elevation= '); %Position
G= 9.8; %Gravity
t=0:.01:1000; %# of Calculations

% math/graphics

f= t*V*cosd(angle); %Flight "X component"
h1= p+t*V*sind(angle) - 1/2*G*t.^2; %Height1 "Y component"
pause(0.1); plot(f,h1,'-'); hold on; %Plot
set(gca,'ylim',[0,max(h1)+(max(h1)/4)]) %Graphical restrictions
xlabel('Distance (m)'); ylabel('Height (m)'); %Labels
heightmax = max(h1)


% outputs

% for loop
for k=1:length(h1),
if h1(k)>0,
xp(k)=f(k);
yp(k)=h1(k);
end
end
distance = max(f(k))

a=1:0.1:45;

for k= 1:length(a),
x= t*V*cosd(a(k));
if x == f,
a2=x;
end
end

h2=p+t*V*sind(angle) - 1/2*G*t.^2;
plot(xp,yp,'-'); hold on; plot(x,h2,'-r');
From: Walter Roberson on
William wrote:
> Hi, Im trying to figure out a way to display a "range" for the given
> function below. However, the number I would like to display as the
> "range" of this function should only be the last positive value along
> the x axis. Any insight is apperciated.


lastindex = find(y>0, 1, 'last');
plot(x(1:lastindex),y(1:lastindex))


Don't know what you plan to do if the user requests an angle of 0 or a
velocity of 0...