%1 DOF motion in 1D

%Initial conditions
t0=0; x0=0; v0=-1;
t1= 2*pi;   %final time

%Material Constants
k= 1;  m = 1; c=.1; g=10;
h = .001 ;  % h = delta t
tarray = [t0]; xarray=[x0]; varray = [v0];
n = (t1-t0)/h;  % Number of time steps

t= t0; x = x0; v = v0;  % initialize variables

%Loop for predicting motion.
for i=1:n

% Model and Material Properties
F = - k *x - c*v;    %damped oscillator
% F =  sin(t);       %sinusoidal force

a = F/m;       %Linear Momentum Balance

t = t + h;
x = x + v*h;   %Kinematics
v = v + a*h;   %Kinematics

tarray = [tarray t];  %Note: horrible for time spent...
xarray = [xarray x];  % in memory allocation, should...
varray = [varray v];  % start with varray = zeros(1,n).

end

plot(tarray, xarray)
title('Andy''s Plot','fontsize', 15)