No BSD License  

Highlights from
Nlsqbnd

from Nlsqbnd by Alain Barraud
Non linear Leasr Squares Solver with box constraints/

testnlsqbnd
function testnlsqbnd
p=20;
pbname={'Watson 6','Watson 9',' Rosenbrock','Powell',' Brown','Wood 6x4','Box 3 21','Meyer'};
problem={@(x) LSwatson(x),@(x) LSwatson(x),@(x) LSrosenb(x),@(x) LSpowell(x),@(x) LSBrown(x,p),...
    @(x) LSwood(x),@(x) LSBox(x),@(x) LSMeyer(x)};
x0={ones(6,1),ones(9,1),[-1.2;1],[3 -1 0 1],[1 1],[-3 -1 -3 -1],[0;10;20],[0.02 4000 250]};
xth={[],[],[1 1],[0 0 0 0],[2^p 5*2-p],[1 1 1 1],[10,1,-1],[]};
fth={[],[],0,0,0,0,0,[]};
lb={[],[],[],[],[],[],[-inf;-inf;0],[]};
ub={[],[],[],[],[],[],[5;inf;inf],[]};
%call nlsqbnd tests
disp('test syntax call')
x=nlsqbnd(@(x) (x-ones(2,1)).^2,[10;5])
x=nlsqbnd(problem{5},x0{5})
x=nlsqbnd(@LSBrown,x0{5},[],[],[],p)
option=optimset('Jacobian','on','display','iter');
x=nlsqbnd(@LSBrown,x0{5},[0;0],[],option,p);
x=nlsqbnd(@LSBrown,x0{5},[0;0],[1e6 1],option,p);
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('%      Performances tests  Analytical Jacobian              ')
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp(' ')
option=optimset('Jacobian','on','display','off');
%computing tests
for k=1:length(problem)
    disp(['Problem name : ',pbname{k}]);
    if isempty(xth{k})
        disp('x_th and f_th unknown')
    else
        disp(['x_th = ',num2str(xth{k},'%23.15e')])
        disp(['f_th = ',num2str(fth{k},'%23.15e')]); 
    end
    disp('%%%%%%%%%%%%%%')
    disp('Solver name nlsqbnd');
    disp('****************************')
    [x,resnorm,residual,exitflag,output,cov,sigx]=nlsqbnd(problem{k},x0{k},lb{k},ub{k},option);
    disp([' f(x) calls = ',num2str(output.funcCount)]);
    disp(['x_est = ',num2str(x(:)','%23.15e')]);
    disp(['f_est = ',num2str(resnorm,'%23.15e')]); 
    disp('********************************************************************************************************************')
    if exist('lsqnonlin','file')==2
        disp('Solver name lsqnonlin');
        disp('****************************')
        [x,resnorm,residual,exitflag,output] =lsqnonlin(problem{k},x0{k},lb{k},ub{k},option);
        disp([' f(x) calls = ',num2str(output.funcCount)]);
        disp(['x_est = ',num2str(x(:)','%23.15e')]);
        disp(['f_est = ',num2str(resnorm,'%23.15e')]);
    end
    disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
    disp(' ')
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('%      Performances tests  Numerical  Jacobian              ')
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp(' ')
option=optimset('Jacobian','off','display','off');
for k=1:length(problem)
    disp(['Problem name : ',pbname{k}]);
    if isempty(xth{k})
        disp('x_th and f_th unknown')
    else
        disp(['x_th = ',num2str(xth{k},'%23.15e')])
        disp(['f_th = ',num2str(fth{k},'%23.15e')]); 
    end
    disp('%%%%%%%%%%%%%%')
    disp('Solver name nlsqbnd');
    disp('****************************')
    [x,resnorm,residual,exitflag,output,Cov]=nlsqbnd(problem{k},x0{k},lb{k},ub{k},option);
    disp([' f(x) calls = ',num2str(output.funcCount)]);
    disp(['x_est = ',num2str(x(:)','%23.15e')]);
    disp(['f_est = ',num2str(resnorm,'%23.15e')]); 
    disp('********************************************************************************************************************')
    if exist('lsqnonlin','file')==2
        disp('Solver name lsqnonlin');
        disp('****************************')
        [x,resnorm,residual,exitflag,output] =lsqnonlin(problem{k},x0{k},lb{k},ub{k},option);
        disp([' f(x) calls = ',num2str(output.funcCount)]);
        disp(['x_est = ',num2str(x(:)','%23.15e')]);
        disp(['f_est = ',num2str(resnorm,'%23.15e')]);
        disp('********************************************************************************************************************')
    end
    disp('Solver name LMFsolve');
    disp('****************************')
    [x, resnorm, CNT,nfeval] = LMFsolve(problem{k},x0{k},'XTol',1e-6,'FunTol' ,1e-6);
    disp([' f(x) calls = ',num2str(nfeval)]);
    disp(['x_est = ',num2str(x(:)','%23.15e')]);
    disp(['f_est = ',num2str(resnorm,'%23.15e')]);
    disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Contact us at files@mathworks.com