% OBJECTIVE FUNCTION
f = @(x,b) b(1)./(1+exp(b(2)-b(3)*x))

% PROBLEM SETUP

dim = 3 % dimension of the minimization problem
nb = 9 % number of points

% NIST certified values
target = zeros(dim,1);
target(1) = 7.2462237576E+01;
target(2) = 2.6180768402E+00;
target(3) = 6.7359200066E-02;

% start 1
ig1 = [100;1;0.1]

% start 2
ig2 = [75;2.5;0.07]

% points to fit
x = zeros(nb,1)
y = zeros(nb,1)
x(1)=9;	y(1)=8.93
x(2)=14;	y(2)=10.8
x(3)=21;	y(3)=18.59
x(4)=28;	y(4)=22.33
x(5)=42;	y(5)=39.35
x(6)=57;	y(6)=56.11
x(7)=63;	y(7)=61.73
x(8)=70;	y(8)=64.62
x(9)=79;	y(9)=67.08


% GRAPHIC REPRESENTATION
scatter(x,y)

% OPTIMIZATION 
rng(0)	% for tractability 
[b,info] = lsqcurvefit(f,ig1,x,y)	% running minimization 

% ANIMATION
% Uncomment the following code to generate animation % 
% rng(0)
% [~,info] = lsqcurvefit(f,ig1,x,y)
% info.plot = 'fit'
% info.animate = true	% plot animation 
% optimview('lsqcurvefit',info) 