
clear
close all

disp('                          VELOCITY                ')
disp(' ')
disp('  Here is curve t -> P(t) = (t, .5*t^2), for t between  0 and 2 .')

f = inline('.5*t.^2');
    t = linspace( 0, 2, 201);
    plot(t, f(t))
    axis equal

disp(' When t = 1/2, the curve passes through the point P0 = (1/2,1/8). ' )
 hold on
 plot(.5, f(.5), '*')

   pause

  disp(' Now we attach several secant vectors attached at P0 .')
  v1 = [1.5, f(2)-f(.5)];
  v2 = [1, f(1.5)-f(.5)];
  v3 = [.6, f(1.1)-f(.5)];
  v4 = [.3, f(.8)-f(.5)];
  p =[.5,f(.5)];
  arrow(p, v1); 
  arrow(p, v2); 
  arrow(p, v3);
  arrow(p, v4);
  
  
   pause
   disp(' We divide each secant vector by delta t (black arrows).')
   arrow(p,v1/1.5, 'k')
   arrow(p,v2,'k')
   arrow(p,v3/.6,'k')
   arrow(p,v4/.3, 'k') 
  disp(' The secant vectors tend to the velocity vector (red).')
  arrow(p, [1, .5], 'r')
  hold off
  pause
 
  disp('  ')
  disp('Here is the curve again with the vel. vector attached at several points .')
  plot(t,f(t))
  hold on

  arrow([.2, f(.2)], [1,.2], 'r')
  arrow([.6, f(.6)], [1, .6], 'r')
  arrow([1, f(1)], [1, 1], 'r')
  arrow([1.4, f(1.4)], [1,1.4], 'r')

  axis equal
  hold off
  
  pause
  disp('  ')
  disp(' The same curve, with a moving bead showing how the ')
  disp(' speed = norm(velocity) = sqrt(1+t^2) changes.')
  disp(' ')
  disp(' First we make the movie ')

  clear t
  t = linspace(-2,2, 101);
  
  plot(t, .5*t.^2)
  hold on
  N = moviein(81);
  ss = linspace(-2,2, 81);
  for j = 1:81
    s = ss(j);
    h = plot(s ,.5*s.^2, '*r');
    N(j) = getframe;
    delete(h)
  end
  disp(' ')
  disp(' Now we run the movie twice  ')
  pause
  movie(N,1)
    



  pause
  clf 
  disp(' ')
  disp('Here is the cycloid curve with velocity vectors attached ')
  clear t
  t = linspace(0, 4*pi, 201);
  s = linspace(0, 4*pi, 16);
  plot(t-sin(t), 1-cos(t), 'k')
  hold on
  plot([-1, 4*pi+1], [0,0])
  axis equal
  for j = 1:16
     p = [s(j)-sin(s(j)), 1-cos(s(j))];
     v = [1-cos(s(j)), sin(s(j))];
     arrow(p,v, 'r')
  end
  hold off

  pause
  disp(' ')
  disp(' Here is movie of the rolling wheel and the light  ')
  disp(' First we make the movie ')
  clear
  clf

  tau = linspace(0, 2*pi, 101);
  s = linspace(0, 4*pi, 201);
     plot(s -sin(s), 1-cos(s), 'k')
     hold on
     plot([-1 4*pi+1], [0,0])
     axis equal
    M = moviein(41);
    for j = 0:120
      t = j*pi/30;
      h1 = plot(t+cos(tau),1+sin(tau));
      h2 = plot(t-sin(t), 1-cos(t), '*r');
      M(:,j+1) = getframe;
      delete(h1); delete(h2)
 end
 hold off
 pause 
 disp(' Now we run the movie twice ')

 movie(M,1)
 
 
 
 

 
  
  
   


    
