From: Walter Roberson on 27 Jul 2010 15:34 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 > > %% > h= t*V*cos(angle); %height > f= p+t*V*sin(angle) - 1/2*G*t.^2; %flight > plot(h,f,'-'); > set(gca,'xlim',[0,length(h)/2],'ylim',[0,(max(f)+5)]) %Graphical > restrictions > % note the +5 in max(f)+5 is only to grow the graph slightly, for later > annotation % space. > > Just about any input you can imagine doesnt allow the x format to work > correctly, but here are some. > > angle = 45 > velocity = 55 > position = 10 > > or > > angle = 45 > velocity = 155 > position = 10 angle = 45 sin(angle) is going to give the sine of 45 *radians*.
From: Alan B on 27 Jul 2010 15:38 "Alan B" <monguin61REM(a)OVETHIS.yahoo.com> wrote in message <i2nc7m$5f7$1(a)fred.mathworks.com>... > "William " <william.baxter(a)oit.edu> wrote in message <i2nblf$rj8$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 > > > > %% > > h= t*V*cos(angle); %height > > f= p+t*V*sin(angle) - 1/2*G*t.^2; %flight > > plot(h,f,'-'); > > set(gca,'xlim',[0,length(h)/2],'ylim',[0,(max(f)+5)]) %Graphical restrictions > > > > % note the +5 in max(f)+5 is only to grow the graph slightly, for later annotation > > % space. > > > > Just about any input you can imagine doesnt allow the x format to work correctly, but here are some... > > Maybe you should use max(h) WITHOUT dividing by 2? > > I don't know why you can't just use this very straightforward solution: > set(gca,'xlim',[min(h), max(h)],'ylim',[min(f), max(f)]) %Graphical restrictions Sorry, I misread the original question. Try this: zeroind = find(f<0,1); set(gca,'xlim',[min(h), h(zeroind)],'ylim',[f(zeroind), max(f)]) %Graphical restrictions
From: William on 27 Jul 2010 15:52 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?
From: Walter Roberson on 27 Jul 2010 15:53 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); %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? Have you considered using cosd() and sind() instead of sin() and cos() ?
From: William on 27 Jul 2010 16:24
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). |