From: Alan B on
"William " <william.baxter(a)oit.edu> wrote in message <i2nddn$nnh$1(a)fred.mathworks.com>...
> angle = input('Enter angle of trajectory= '); %Angle
> V= input('Enter velocity= '); %Velocity
> p= input('Enter Position of elevation= '); %Position
> G= 9.8; %Gravity
> t=0:0.1:20; %# of Calculations
>
> %%
> h1= t*V*cos(angle); %height
> f= p+t*V*sin(angle) - 1/2*G*t.^2; %flight
> h2=t*(V+25)*cos(angle); %height component 2
> h3=t*(V+50)*cos(angle);
> h4=t*(V+75)*cos(angle);
> plot(h1,f,'-');hold on;plot(h2,f,'-r');plot(h3,f,'-g');plot(h4,f,'-y');
> set(gca,'xlim',[0, max(h4)],'ylim',[0, max(f)]) %Graphical restrictions
>
> It seems this has issues when graphing angles other than 45. It will always return plots in the negative direction. is there a way to restrict this?

As others have mentioned, you need to use cosd and sind, or convert your angles to radians. Until you do that, your angle variable will be misleading. After you fix this, it will be easier to avoid plots with a leftward trajectory. If you want to be able to show both directions, you will need some sort of additional logic to deal with the limits on the x axis.

If the initial SPEED is modified (by adding 25, 50, 75), BOTH dimensions will be affected, not just the horizontal dimension.

It is probably best to use "axis equal" when your plot axes represent physical units of equal size.

This is just a notation issue, but: you are calling the horizontal position component "height", which goes against the convention. Generally the dimension that is affected by gravity is called height, and is shown on the vertical axis.
From: us on
On Jul 27, 10:24 pm, "William " <william.bax...(a)oit.edu> wrote:
> angle = input('Enter angle of trajectory= '); %Angle
> V= input('Enter velocity= '); %Velocity
> p= input('Enter Position of elevation= '); %Position
> G= 9.8; %Gravity
> t=0:0.1:20; %# of Calculations
>
> %%
> h1= t*V*cos(angle/180); %height
> f= p+t*V*sin(angle/180) - 1/2*G*t.^2; %flight
> plot(h1,f,'-');hold on; xlabel('Distance (m)'); ylabel('Height (m)');
>
> ....Yes you are correct, in the same way dividing angle/180 works. However i still cannot restrict my y axis correctly. I do not want it to show negative values of y (or when the projectile would be below the surface).

then use(!)...

...'ylim',[0 whatever]...

us
From: Walter Roberson on
William wrote:
> angle = input('Enter angle of trajectory= '); %Angle
> V= input('Enter velocity= '); %Velocity
> p= input('Enter Position of elevation= '); %Position
> G= 9.8; %Gravity
> t=0:0.1:20; %# of Calculations
>
> %%
> h1= t*V*cos(angle/180); %height
> f= p+t*V*sin(angle/180) - 1/2*G*t.^2; %flight
> plot(h1,f,'-');hold on; xlabel('Distance (m)'); ylabel('Height (m)');
>
> ....Yes you are correct, in the same way dividing angle/180 works.

Dividing the angle by 180 does not convert it to radians.

360 degrees is 2*pi radians, so
180 degrees is pi radians.

Your code would calculate 180 degrees as 1 radian instead.
From: Walter Roberson on
William wrote:

> However i still cannot restrict my y axis correctly. I do not want it to
> show negative values of y (or when the projectile would be below the
> surface).

ylim() with 0 as the lower bound and max(f(:)) as your upper bound.
From: William on
Walter Roberson <roberson(a)hushmail.com> wrote in message <i2nfkk$nqf$3(a)canopus.cc.umanitoba.ca>...
> William wrote:
>
> > However i still cannot restrict my y axis correctly. I do not want it to
> > show negative values of y (or when the projectile would be below the
> > surface).
>
> ylim() with 0 as the lower bound and max(f(:)) as your upper bound.


This works on the ylim, but its because you can restrict the lower limit to 0...The calculations continue further negative, but as the restriction is zero you dont get to see them. The max will work on the principal that the ymax is actually just that.

However, when doing these calculations on the xaxis the max of x is actually calculated below the y axis. I think i need to some how tell my program to stop calculating once y equal to or less than zero.