function [x,fval,iterations,funcCount,firstorderopt,lambda_lower,lambda_upper]=optim_output(opt_type,algorithm)

% initial point
x0=[10^5 0.8 2 8 0.7];

% bound constraints
lb=[10^3 0.7 1 0.1 0];
ub=[10^6 1 4 10 1];

% Runs fmincon function with user-selected algorithm if opt_type=1,
% otherwise runs lsqnonlin function
if opt_type==1
    % Maximum function evaluations and iterations increased from default,
    % default values of tolerances used
    options=optimset('Algorithm',algorithm,'MaxFunEvals',10^4,'MaxIter',10^4,'TolX',1e-6,'TolFun',1e-6,'PlotFcns',{@optimplotfval @optimplotfirstorderopt});
    % Empty matrices indicate no linear and nonlinear constraints
    [x,fval,exitflag,output,lambda]=fmincon(@f_con_high,x0,[],[],[],[],lb,ub,[],options);
    exitflag % indicates why the optimization routine was exited
else
    % Maximum function evaluations and iterations increased from default,
    % default values of tolerances used
    options=optimset('Algorithm',algorithm,'MaxFunEvals',10^4,'MaxIter',10^4,'TolX',1e-6,'TolFun',1e-6,'PlotFcns',{@optimplotresnorm @optimplotfirstorderopt});
    [x,resnorm,residual,exitflag,output,lambda]=lsqnonlin(@f_lsq_high,x0,lb,ub,options);
    fval=resnorm; % norm of the residuals
    exitflag % indicates why the optimization routine was exited
end

iterations=output.iterations; % number of iterations
funcCount=output.funcCount; % number of function evaluations
firstorderopt=output.firstorderopt; % final value of the first order optimality criteria
lambda_lower=lambda.lower; % final Langrange multiplier for the lower bound constraints
lambda_upper=lambda.upper; % final Langrange multipliers for the upper bound constraints

end