% =================================================================
% sdof.m -- Compute dynamic response of sdof system.
%
% Written By : Mark Austin                               March 1997
% =================================================================

% Setup array for storing and plotting system response

  nopoints = 501;
  response = zeros(nopoints,3);

% Problem parameters and initial conditions

  mass  = 1;
  stiff = 10;
  w     = sqrt(stiff/mass);
  dt    = 0.02;

  displ0    =  1;
  velocity0 = 10;

% Compute displacement and velocity time history response

  for i = 1 : nopoints
      time = (i-1)*dt;
      response(i,1) = time;
      response(i,2) =  displ0*cos(w*time)   + velocity0/w*sin(w*time);
      response(i,3) = -displ0*w*sin(w*time) + velocity0*cos(w*time);
  end

% Plot displacement versus time

  plot(response(:,1), response(:,2));
  hold;

% Plot velocity versus time

  plot(response(:,1), response(:,3));

  grid;
  xlabel('Time (seconds)');
  ylabel('Displacement (m) and Velocity (m/sec)');
  title('Time-History Response for SDOF Oscillator');
