
%%
nn = 5; % number of inner points
x0 = linspace(0.1, 0.9, nn) + randn(1,nn)*0.01;
y0 = zeros(1,nn) - rand(1,nn)*.25;

p0 = [x0 y0];
drawChain(p0)

%% optimize using gradient descent (fminsearch)
p_opt = fminsearch(@chainEnergy,p0);

%% optimize using gradient descent (fminunc)
p_opt = fminunc('chainEnergy',p0);

%% optimize using simulated annealing
p_opt = simulannealbnd(@chainEnergy,p0);

