% Euler integratior for system
% m du/dt = -S(x-R)-Du
% dx/dt = u
% Following Charlie's notes
% u(t+dt)=u(t)+dt*[-S*(x(t)-R)-D*u(t)]
% x(t+dt)=x(t)+dt*u(t+dt)
R = 1; % spring rest length
S = 1; % stiffnes
m = 1; % mass of pt
D = 0; % damping coeff
% Initial conditions, final time, time step
x0 = 1;
u0 = 1;
T = 10;
dt = 1e-2;
numSteps = T/dt;
xvals = zeros(numSteps+1,1);
xvals(1) = x0;
uvals = zeros(numSteps+1,1);
uvals(1) = u0;
for i=1:numSteps
    uvals(i+1)=uvals(i)+dt*(-S*(xvals(i)-R)-D*uvals(i));
    xvals(i+1)=xvals(i)+dt*uvals(i+1);
end
tvals = 0:dt:T;
plot(tvals,xvals)
hold on
plot(tvals,uvals)
