% rotating_vector plots a time-dependent point and vector % following problem 7.2.4 in "Basic Training in Mathematics" % by R. Shankar. % % Programmer: Dick Furnstahl furnstahl.1@osu.edu % % Revision history: % 01-May-2005 -- original version for Physics 263 % clear; clf; % clear variables and figures omega = 1; % set the frequency t_start = 0.0; % starting time t_end = 10.0; % ending time delta_t = 0.1; % time between points plotted % set up a vector from t_start to t_end spaced by delta_t t = t_start : delta_t : t_end; x = cos(omega*t); % evaluate at all t points y = sin(omega*t); % evaluate at all t points % use a for loop to step through the time points one-by-one for t0 = t_start : delta_t : t_end x0 = cos(omega*t0); % the current x position y0 = sin(omega*t0); % the current y position vx0 = -omega*sin(omega*t0); % ??? vy0 = omega*cos(omega*t0); % ??? plot(x0,y0,'ro'); % plot the current point with a red circle ('ro') axis([-1.5 1.5 -1.5 1.5]); axis square; % set the axis dimensions hold on; % hold the plot so we can add more plots scale = 1.0; % scale factor for vectors % quiver will plot a vector based at x0,y0 with x and y % components vx0,vy0, scaled by scale, in red ('r') quiver(x0,y0,vx0,vy0,scale,'r'); plot(x,y,'b'); % plot the entire trajectory in blue ('b') hold off; % release the hold pause(.1); % pause this fraction of a second end