From: us on
"William " <william.baxter(a)oit.edu> wrote in message <i2no0g$o32$1(a)fred.mathworks.com>...
> Hi, I am trying to write a function to preform calculations and display a curve.
> I want these calculations to end once its Y value is equal to zero, and display only what was calculated. Any insight helps!
>
> Here is what i have:
>
>
> %% Inputs
>
> 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:20; %# of Calculations
>
> %% math/graphics
>
> f= t*V*cosd(angle); %Flight
> h1= p+t*V*sind(angle) - 1/2*G*t.^2; %Height
> plot(f,h1,'-');pause(0.1); hold on; %Plot
> set(gca,'ylim',[0,max(h1)+(max(h1)/4)]) %Graphical restrictions
> xlabel('Distance (m)'); ylabel('Height (m)'); %Labels
> heightmax = max(h1);
>
>
> Try angle = 65, velocity = 125, position = 0...notice how far it calculates past 0...how can i restrict this?

1) using your input, Y does not get ...past 0... (assuming this means neg vals)...
2) use indexing, eg,

ix=h1>=0;
% or
ix=find(h1<0,1,'first');
% to restrict F and H1

us
 | 
Pages: 1
Prev: rescaling for fmincon
Next: Easy array question