% OBJECTIVE FUNCTION
f = @(x,b) b(1)*exp(-b(2)*x) + b(3)*exp(-b(4)*x) + b(5)*exp(-b(6)*x)

% PROBLEM SETUP

dim = 6 % dimension of the minimization problem
nb = 24 % number of points

% NIST certified values
target = zeros(dim,1);
target(1) = 8.6816414977E-02;
target(2) = 9.5498101505E-01;
target(3) = 8.4400777463E-01;
target(4) = 2.9515951832E+00;
target(5) = 1.5825685901E+00;
target(6) = 4.9863565084E+00;

% start 1
ig1 = [1.2;0.3;5.6;5.5;6.5;7.6]
% start 2
ig2 = [0.5;0.7;3.6;4.2;4;6.3]

% points to fit
x = zeros(nb,1)
y = zeros(nb,1)
x(1)=0;	y(1)=2.5134
x(2)=0.05;	y(2)=2.0443
x(3)=0.1;	y(3)=1.6684
x(4)=0.15;	y(4)=1.3664
x(5)=0.2;	y(5)=1.1232
x(6)=0.25;	y(6)=0.9269
x(7)=0.3;	y(7)=0.7679
x(8)=0.35;	y(8)=0.6389
x(9)=0.4;	y(9)=0.5338
x(10)=0.45;	y(10)=0.4479
x(11)=0.5;	y(11)=0.3776
x(12)=0.55;	y(12)=0.3197
x(13)=0.6;	y(13)=0.272
x(14)=0.65;	y(14)=0.2325
x(15)=0.7;	y(15)=0.1997
x(16)=0.75;	y(16)=0.1723
x(17)=0.8;	y(17)=0.1493
x(18)=0.85;	y(18)=0.1301
x(19)=0.9;	y(19)=0.1138
x(20)=0.95;	y(20)=0.1
x(21)=1;	y(21)=0.0883
x(22)=1.05;	y(22)=0.0783
x(23)=1.1;	y(23)=0.0698
x(24)=1.15;	y(24)=0.0624


% 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 
% info.animfreq = 6	% frame frequency 
% optimview('lsqcurvefit',info) 