%% 2D elastic chain using generalized n-points code
%
t = 0:0.01:10;
n = 7;
x0 = 0; y0 = 0;
xn = 5; yn = 0;
m = 0.5/n; k = 50; b = 0.03;
x_init = linspace(x0,xn,n+2)'; x_init = x_init(2:end-1);
y_init = zeros(n,1);
Lr = (xn-x0)/(n+1);
state0 = [x_init; y_init; zeros(n,1); zeros(n,1)]; % x;y;xd;yd
myfun = @(t,state) spring2Dn(t,state,n,m,k,b,x0,y0,xn,yn,Lr);
[t,state] = ode45(myfun, t, state0);
figure
AnimateChain(t,state,x0,y0,xn,yn);

