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

조회 수: 4 (최근 30일)
Alex
Alex 2011년 12월 15일
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?

답변 (2개)

Walter Roberson
Walter Roberson 2011년 12월 15일
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 2011년 12월 15일
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
Alex
Alex 2011년 12월 15일
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’)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by