Prev: Error
Next: face color database
From: William on 31 Jul 2010 06:57 Hello, I am trying to plot a red "dot" at the maximum Y value. Here is what i have so far. function Trajectory % trajectory: function to solve trajectory motion with inputs of angle % velocity, and position. This function will also give trajectory for % the alternate angular value. Or +180 degrees. % % 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 of projectile (m/sec)= '); %Velocity p= input('Enter Position of elevation= '); %Position G= 9.8; %Gravity (earth) 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)'); %Ladbels heightmax = max(h1) %max height % for loops for k=1:length(h1), %restricts negative values of x in plot if h1(k)>0, xp(k)=f(k); yp(k)=h1(k); end end distance = (V.^2*sind(2.*angle))/G %Distance of flight a=1:0.1:45; for k= 1:length(a), %Loop for same range, but alt x= t*V*cosd(a(k)); %angle if x == f, a2=x; end end a2=180:0.1:360; for k= 1:length(h1), if h1(k)==max(h1), plot(max(h1),max(f)*2,'r-') end end %Plots and annotation h2=p+t*V*sind(angle) - 1/2*G*t.^2; %alternate angle with same max height plot(xp,yp,'-'); hold on; plot(x,h2,'-r'); box off; grid on; %graphics legend('Original Trajectory Angle','Alternate Trajectory Angle',2); %legend text((max(h1)+((3/2)*max(h1))),(max(h1)+((1/50).*max(h1))),... %annotation 'maximum height','FontSize',8) title(sprintf('approx. max height = %-6.0f m\n', max(h1))) %title with %max height
From: us on 31 Jul 2010 07:07 "William " <william.baxter(a)oit.edu> wrote in message <i30vi1$sd5$1(a)fred.mathworks.com>... > Hello, I am trying to plot a red "dot" at the maximum Y value. Here is what i have so far. did you look at replies to your former OPs dealing with the issue of logical indexing(?)... this shall be helpful to solve this simple problem... us
From: William on 31 Jul 2010 18:02 "us " <us(a)neurol.unizh.ch> wrote in message <i3104p$5f6$1(a)fred.mathworks.com>... > "William " <william.baxter(a)oit.edu> wrote in message <i30vi1$sd5$1(a)fred.mathworks.com>... > > Hello, I am trying to plot a red "dot" at the maximum Y value. Here is what i have so far. > > did you look at replies to your former OPs dealing with the issue of logical indexing(?)... > this shall be helpful to solve this simple problem... > > us Hi, yes I have refered to the logical() information. I think I have the idea if you could point me in the right direction with syntax it would be greatly apperciated. Here is what I have. function Trajectory % trajectory: function to solve trajectory motion with inputs of angle % velocity, and position. This function will also give trajectory for % the alternate angular value. Or +180 degrees. % % y = trajectory_motion(angle,V,p) % % angle = Angle of trajectory % V = Velocity % p = Position from x-axis. % % Inputs close all; angle = input('Enter angle of trajectory (degrees)= '); %Angle V= input('Enter velocity of projectile (m/sec)= '); %Velocity p= input('Enter Position of elevation= '); %Position G= 9.8; %Gravity (earth) t=0:.01:1000; %# of Calculations % math/graphics format short; 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)'); %Ladbels heightmax = max(h1) %max height % for loops for k=1:length(h1), %restricts negative values of x in plot if h1(k)>0, xp(k)=f(k); yp(k)=h1(k); end end format short; distance = (V.^2*sind(2.*angle))/G %Distance of flight a=1:0.1:45; for k= 1:length(a), %Loop for same range, but alt x= t*V*cosd(a(k)); %angle if x == f, a=x; end end for k= 1:length(h1), if h1(k)==max(h1), plot(max(h1),max(f)*2,'-r') end end K=logical(xp>0); plot(((K).*(1/2)),max(yp),'or'); %Plots and annotation h2=p+t*V*sind(angle) - 1/2*G*t.^2; %alternate angle with same max height plot(xp,yp,'-'); hold on; plot(x,h2,'-r'); box off; %graphics legend('Alternative Trajectory Angle','Original Trajectory Angle',2); %legend text((max(h1)+((3/2)*max(h1))),(max(h1)+((1/50).*max(h1))),... %annotation 'maximum height','FontSize',8) title(sprintf('approx. max height = %-6.0f m\n', max(h1))) %title with max K=logical(xp>0); plot(((K).*(1/2)),max(yp),'or'); <<<QUESTION. my idea was that using the logical command where the x values are greater than 0 would create an array the same size as my positive range. The coresponding coordinates then should be ((1/2) my range (or now "K"),max(Yvalue)) hope this makes sense, any help is apperciated.
From: William on 31 Jul 2010 19:47 "William " <william.baxter(a)oit.edu> wrote in message <i326gt$gka$1(a)fred.mathworks.com>... > "us " <us(a)neurol.unizh.ch> wrote in message <i3104p$5f6$1(a)fred.mathworks.com>... > > "William " <william.baxter(a)oit.edu> wrote in message <i30vi1$sd5$1(a)fred.mathworks.com>... > > > Hello, I am trying to plot a red "dot" at the maximum Y value. Here is what i have so far. > > > > did you look at replies to your former OPs dealing with the issue of logical indexing(?)... > > this shall be helpful to solve this simple problem... > > > > us > > > Hi, yes I have refered to the logical() information. I think I have the idea if you could point me in the right direction with syntax it would be greatly apperciated. Here is what I have. > > > > > function Trajectory > % trajectory: function to solve trajectory motion with inputs of angle > % velocity, and position. This function will also give trajectory for > % the alternate angular value. Or +180 degrees. > % > % y = trajectory_motion(angle,V,p) > % > % angle = Angle of trajectory > % V = Velocity > % p = Position from x-axis. > % > % Inputs > > close all; > > angle = input('Enter angle of trajectory (degrees)= '); %Angle > V= input('Enter velocity of projectile (m/sec)= '); %Velocity > p= input('Enter Position of elevation= '); %Position > G= 9.8; %Gravity (earth) > t=0:.01:1000; %# of Calculations > > % math/graphics > > format short; > 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)'); %Ladbels > heightmax = max(h1) %max height > > > % for loops > for k=1:length(h1), %restricts negative values of x in plot > if h1(k)>0, > xp(k)=f(k); > yp(k)=h1(k); > end > end > > format short; > distance = (V.^2*sind(2.*angle))/G %Distance of flight > a=1:0.1:45; > > for k= 1:length(a), %Loop for same range, but alt > x= t*V*cosd(a(k)); %angle > if x == f, > a=x; > end > end > > > for k= 1:length(h1), > if h1(k)==max(h1), > plot(max(h1),max(f)*2,'-r') > end > end > K=logical(xp>0); plot(((K).*(1/2)),max(yp),'or'); > > %Plots and annotation > > h2=p+t*V*sind(angle) - 1/2*G*t.^2; %alternate angle with same max height > plot(xp,yp,'-'); hold on; plot(x,h2,'-r'); box off; %graphics > legend('Alternative Trajectory Angle','Original Trajectory Angle',2); %legend > text((max(h1)+((3/2)*max(h1))),(max(h1)+((1/50).*max(h1))),... %annotation > 'maximum height','FontSize',8) > title(sprintf('approx. max height = %-6.0f m\n', max(h1))) %title with max > K=logical(xp>0); plot(((K).*(1/2)),max(yp),'or'); > > <<<QUESTION. my idea was that using the logical command where the x values are greater than 0 would create an array the same size as my positive range. The coresponding coordinates then should be ((1/2) my range (or now "K"),max(Yvalue)) > hope this makes sense, any help is apperciated. > Anyone?
From: Matt Fig on 31 Jul 2010 20:54
An example: % Data x = -10:.1:10; y = -(x+2).^2+3; % Engine [loc,loc] = max(y); plot(x,y,'-b',x(loc),y(loc),'*r') |