Having problems understanding the command y( size(t) ) in a plot.

4 views (last 30 days)
The whole command is given as:
plot(x,y,’k’,xmax,y(size(t)),’o’,xmax/2,ymax,’o’)
x, y, xmax, t, and ymax are all assigned variables. However I have no idea what the size command does. Does anyone know what this does?

Answers (2)

Walter Roberson
Walter Roberson on 15 Dec 2011
It is a fancy (and confusing) way to draw a vertical line at xmax that shows the range of y values. It would be clearer to use y([1 end])

bym
bym on 15 Dec 2011
it just plots xmax vs y(size(t)) as a second trace on the plot, but with the same markings as [xmax/2,ymax]...Have to see more code to figure why...
  1 Comment
Alex
Alex on 15 Dec 2011
Here is the program, the command is all the way in the last line. How would the value of y(size(t)) be calculated in this case.
The projectile problem with zero air resistance
% in a gravitational field with constant g.
%
% Written by D. T. Valentine ........ September 2006
% Revised by D. T. Valentine ........ November 2008
% An eight-step structure plan applied in MATLAB:
%
% 1. Definition of the input variables.
%
g = 9.81; % Gravity in m/s/s.
vo = input(’What is the launch speed in m/s? ’);
tho = input(’What is the launch angle in degrees? ’);
tho = pi*tho/180; % Conversion of degrees to radians.
%
% 2. Calculate the range and duration of the flight.
%
txmax = (2*vo/g) * sin(tho);
xmax = txmax * vo * cos(tho);
%
% 3. Calculate the sequence of time steps to compute trajectory.
%
dt = txmax/100;
t = 0:dt:txmax;
% 4. Compute the trajectory.
%
x = (vo * cos(tho)) .* t;
y = (vo * sin(tho)) .* t –(g/2) .* t.ˆ2;
%
% 5. Compute the speed and angular direction of the projectile.
% Note that vx = dx/dt, vy = dy/dt.
%
vx = vo * cos(tho);
vy = vo * sin(tho) –g .* t;
v = sqrt(vx.*vx + vy.*vy);
th = (180/pi) .* atan2(vy,vx);
%
% 6. Compute the time, horizontal distance at maximum altitude.
%
tymax = (vo/g) * sin(tho);
xymax = xmax/2;
ymax = (vo/2) * tymax * sin(tho);
%
% 7. Display ouput.
%
disp([’ Range in m = ’,num2str(xmax), ...
’ Duration in s = ’, num2str(txmax)])
disp(’ ’)
disp([’ Maximum altitude in m = ’,num2str(ymax), ...
’ Arrival in s = ’, num2str(tymax)])
plot(x,y,’k’,xmax,y(size(t)),’o’,xmax/2,ymax,’o’)

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!