Code covered by the BSD License  

Highlights from
Rosin-Rammler Diagram plotting tool

image thumbnail

Rosin-Rammler Diagram plotting tool

by

 

25 Jun 2010 (Updated )

This tool plots the Rosin-Rammler Diagram (RRSB) and calculates various related parameters.

createExitMsg(caller,exitflag,dispMsg,detailedExitMsg,varargin)
function outputMsg = createExitMsg(caller,exitflag,dispMsg,detailedExitMsg,varargin)
%createExitMsg create exit messages for Optimization Toolbox solvers.
%
% This utility creates and displays the exit messages (default and
% detailed) for all Optimization Toolbox solvers.
%
% INPUTS:
% - caller is a string containing the name of the function that originally
% called createExitMsg.
% - exitflag is the flag indicating which exit condition caused the solver to
% stop.
% - dispMsg is a boolean which is true when the message is to be displayed in
% the Command Window.
% - detailedExitMsg is a boolean which is true when the user has selected the
% detailed message via optimset.
% - varargin contains the list of quantities that are to be embedded in the
% message. The list of these quantities varies, but the order must be
% consistent:
% {'topLevelFcn',quantity,optionChoiceString,optionValue,quantity2, ...
% option2ChoiceString,option2Value,...}

%   Copyright 2008-2009 The MathWorks, Inc.
%   $Revision: 1.1.6.9 $  $Date: 2009/11/05 17:01:32 $

enableLinks = feature('hotlinks') && dispMsg && ~isdeployed;

% Define constants for exitflags
stoppedAtX0 = 100;
undefGrads = 26;
dirDeriv = 5;
smallSearchDir = 4;
deltaF = 3;
deltaX = 2;
optimal = 1;
maxFunEval = 0;
maxIter = 10;
outputFcn = -1;
infeasSQP = -20;
infeasStationary = -21;
infeasDeltaX = -22;
infeasDeltaF = -23;
infeasSmallSearchDir = -24;
infeasDirDeriv = -25;
infeasUndefGrads = -26;
unbounded = -3;

% Make sure that there are enough cells (at least 7) in the messageInfo
% array. That is, there must be a uniform amount of inputs to createExitMsg.
% Otherwise, creating the "detail" link in the command window will break.
% varargin will be of length 1,4, or 7. It is never empty.
messageInfo = [varargin,{0,'',0,0,'',0}];

% Initialize basicMsg and detailedMsg
basicMsg = '';
detailedMsg = '';

if enableLinks
    endLinkTag = '</a>';
    % Create template html tag, anchors within CSH are filled in below.
    linkCmd = '<a href = "matlab: helpview([docroot ''/toolbox/optim/msg_csh/optim_msg_csh.map''],''%s'',''CSHelpWindow'');">';
    
    % Fill in template html tag with anchors pointing to CSH
    uncLocalOptTag = sprintf(linkCmd,'local_min_unconstrained');    % exitflag 1: fminusub, sfminbx, sfminle
    lsqLocalOptTag = sprintf(linkCmd,'local_min_lsq');              % exitflag 1: levenbergMarquardt,snls
    uncInitPtTag = sprintf(linkCmd,'initial_local_unc');            % exitflag 100: fminusub, sfminbx, sfminle
    lsqInitPtTag = sprintf(linkCmd,'lsq_init_pt_min');              % exitflag 100: levenbergMarquardt,snls
    normGradTag = sprintf(linkCmd,'first_order_opt_unc');           % exitflag 1,100: fminusub, sfminbx, sfminle,levenbergMarquardt
    gradSizeTag = sprintf(linkCmd,'grad_size');                     % exitflag 1,100: fminusub, sfminbx, sfminle
    regProbTag = sprintf(linkCmd,'appears_regular');                % exitflag 1,100: levenbergMarquardt,snls,trustnleqn
    lsqGradSizeTag = sprintf(linkCmd,'lsq_grad_size');              % exitflag 1,100: levenbergMarquardt,snls
    lsqNormGradTag = sprintf(linkCmd,'firstorder_lsq');             % exitflag 1,100: levenbergMarquardt,snls
    eqSolvInitTag = sprintf(linkCmd,'eq_init_pt');                  % exitflag 100: levenbergMarquardt,snls,trustnleqn
    eqSolvedTag = sprintf(linkCmd,'eqn_solved');                    % exitflag 1: levenbergMarquardt,snls,trustnleqn
    normStepTag = sprintf(linkCmd,'norm_current_step');             % exitflag 2: fminusub,sfminbx, sfminle
    uncPossMinTag = sprintf(linkCmd,'local_min_possible');          % exitflag 2,3: fminusub,sfminbx,sfminle
    eqSolveSingTag = sprintf(linkCmd,'eqn_solved_singular');        % exitflag 2: levenbergMarquardt,snls,trustnleqn (fsolve)
    lsqPossMinTag = sprintf(linkCmd,'local_min_possible_lsq');      % exitflag 2: levenbergMarquardt,snls,trustnleqn (lsqnonlin/curvefit)
    conLocalOptTag = sprintf(linkCmd,'local_min_found');            % exitflag 1: nlconst,barrier,sqpLineSearch
    conInitPtTag = sprintf(linkCmd,'did_not_move');                 % exitflag 100: barrier,sqpLineSearch
    firstOrdOptTag = sprintf(linkCmd,'first_order_opt_con');        % exitflag 1,100: barrier,sqpLineSearch,nlconst
    feasDirTag = sprintf(linkCmd,'feasible_directions');            % exitflag 1,100: barrier,sqpLineSearch,nlconst
    normSearchDirTag = sprintf(linkCmd,'norm_search_direction');    % exitflag 4,-24: nlconst
    searchDirTag = sprintf(linkCmd,'search_direction');             % exitflag 5: fminusub
    conNormStepTag = sprintf(linkCmd,'norm_curr_step_fminconip');   % exitflag 2: barrier,sqpLineSearch
    gradCalcFailTag = sprintf(linkCmd,'grad_calc_failed');          % exitflag 26,-26: sqpLineSearch
    conPossMinTag = sprintf(linkCmd,'local_min_poss_with_constr');  % exitflag 2,3,4,5: all optimizers
    dirDerivTag = sprintf(linkCmd,'pred_change');                   % exitflag 5,-25: all solvers
    lsIntervalTag = sprintf(linkCmd,'line_search_interval');        % exitflag 5: fminusub
    eqSolvedInaccTag = sprintf(linkCmd,'eqn_inaccuracy');           % exitflag 3: levenbergMarquardt,snls,trustnleqn (fsolve)
    ineffectiveStepTag = sprintf(linkCmd,'last_step_ineffective');  % exitflag 3: levenbergMarquardt,snls,trustnleqn (fsolve)
    inFeasTag = sprintf(linkCmd,'no_feasible_point');               % exitflag -20,-21,-22,-24,-25: barrier,sqpLineSearch,nlconst
    unboundedTag = sprintf(linkCmd,'appears_unbounded');            % exitflag -3: barrier,sqpLineSearch
    stationaryConstrTag = sprintf(linkCmd,'constr_viol_flat');      % exitflag -21: barrier
    noEqSolTag = sprintf(linkCmd,'eqn_no_soln');                    % exitflag -21,-22,-23,-24: trustnleqn,levenbergMarquardt,snls
    noEqSolTrrTag = sprintf(linkCmd,'eqn_no_soln_negexit');         % exitflag -3: trustnleqn,levenbergMarquardt,snls
    localSingularTag = sprintf(linkCmd,'local_singular');           % exitflag -3: trustnleqn
    localSingularLSQTag = sprintf(linkCmd,'local_singular_lsq');    % exitflag -3: trustnleqn
    regParamTag = sprintf(linkCmd,'reg_param');                     % exitflag -3: levenbergMarquardt
    trRadiusTag = sprintf(linkCmd,'trr');                           % exitflag -3: trustnleqn
    maxSQPIterTag = sprintf(linkCmd,'maxsqpiter_csh');              % exitflag -20: nlconst
    objectiveLimitTag = sprintf(linkCmd,'objective_limit');         % exitflag -3: barrier,sqpLineSearch
    functionTolTag = sprintf(linkCmd,'function_tolerance');         % exitflag 1,100,3,5,-25: all scalar nonlinear solvers
    tolFunTag = sprintf(linkCmd,'tolfun');                          % exitflag 1,100,3,5,-25: all scalar nonlinear solvers
    functionTolLSQTag = sprintf(linkCmd,'function_tolerance_lsq');  % exitflag 1,100,3,-21,-23: nonlinear lsq solvers
    tolFunLSQTag = sprintf(linkCmd,'tolfun_lsq');                   % exitflag 1,100,3,-21,-23: nonlinear lsq solvers
    funcTolFsolveTag = sprintf(linkCmd,'fcn_tolerance_fsolve');     % exitflag 1,100,3,-21,-23: fsolve
    tolFunFsolveTag = sprintf(linkCmd,'tolfun_fsolve');             % exitflag 1,100,3,-21,-23: fsolve    
    stepSizeTolTag = sprintf(linkCmd,'step_size_tol');              % exitflag 2,-224,-24: all solvers
    tolXTag = sprintf(linkCmd,'tolx');                              % exitflag 2,-24,-24: all solvers
    constrTolTag = sprintf(linkCmd,'constraint_tolerance');         % All exitflags: barrier,sqpLineSearch,nlconst
    tolConTag = sprintf(linkCmd,'tol_con');                         % All exitflags: barrier,sqpLineSearch,nlconst
    maxFunEvalTag = sprintf(linkCmd,'max_fun_evals');               % exitflag 0
    prematureStopTag = sprintf(linkCmd,'solver_stopped_premature'); % exitflag 0,10
    maxIterTag = sprintf(linkCmd,'max_iter');                       % exitflag 10
    outputFcnTag = sprintf(linkCmd,'output_function');              % exitflag -1
    
    % Create html tag for the "<detail>" link
    detailTag = sprintf(['<<a href = "matlab: createExitMsg(''%s'',%e,true,true,''%s'',%e,''%s'',%e,%e,''%s'',%e);">' ...
        'stopping criteria details</a>>'],caller,exitflag,messageInfo{1:7});
else
    % Create tag variables with null strings because links are disabled.
    [uncLocalOptTag,uncInitPtTag,normGradTag,gradSizeTag,normStepTag,uncPossMinTag, ...
        conLocalOptTag,conInitPtTag,firstOrdOptTag,feasDirTag,searchDirTag,conPossMinTag, ...
        dirDerivTag,inFeasTag,unboundedTag,tolFunTag,tolXTag,stepSizeTolTag,tolConTag, ...
        maxFunEvalTag,maxIterTag,outputFcnTag,objectiveLimitTag,detailTag,endLinkTag, ...
        functionTolTag,constrTolTag,maxSQPIterTag,stationaryConstrTag,prematureStopTag, ...
        normSearchDirTag,conNormStepTag,lsIntervalTag,regProbTag,lsqGradSizeTag,eqSolvInitTag, ...
        eqSolvedTag,eqSolveSingTag,eqSolvedInaccTag,ineffectiveStepTag,noEqSolTag,localSingularTag, ...
        regParamTag,trRadiusTag,lsqLocalOptTag,lsqInitPtTag,lsqNormGradTag,noEqSolTrrTag, ...
        localSingularLSQTag,lsqPossMinTag,tolFunLSQTag,functionTolLSQTag,funcTolFsolveTag, ...
        tolFunFsolveTag,gradCalcFailTag] = ...
        deal('');
end

switch exitflag
    case stoppedAtX0 % exitflag = 100
        switch caller
            case {'barrier','sqpLineSearch'}
                % messageInfo = {'fmincon',firstordopt,tolFunChoice,tolFun,maxConstr,tolConChoice,tolCon}
                basicMsg = sprintf(['\n%sInitial point is a local minimum that satisfies the constraints%s.\n\n',...
                    'Optimization completed because at the initial point, the objective function is ', ...
                    'non-decreasing \nin %sfeasible directions%s to within the %s value of the %sfunction tolerance%s, ', ...
                    'and \nconstraints were satisfied to within the %s value of the %sconstraint tolerance%s.\n\n%s\n'], ...
                    conInitPtTag,endLinkTag,feasDirTag,endLinkTag,messageInfo{3},functionTolTag,endLinkTag,messageInfo{6}, ...
                    constrTolTag,endLinkTag,detailTag);
                
                detailedMsg = sprintf(['\nOptimization completed: The final point is the initial point.\n', ...
                    'The %sfirst-order optimality measure%s, %e, is less than\n%soptions.TolFun%s = %e, and ', ...
                    'the maximum constraint\nviolation, %e, is less than %soptions.TolCon%s = %e.\n\n', ...
                    'Optimization Metric                                         Options\n', ...
                    'first-order optimality = %10.2e                TolFun = %7.0e (%s)\n', ...
                    'max(constraint violation) = %10.2e             TolCon = %7.0e (%s)\n'],firstOrdOptTag,endLinkTag, ...
                    messageInfo{2},tolFunTag,endLinkTag,messageInfo{4},messageInfo{5},tolConTag,endLinkTag,messageInfo{7}, ...
                    messageInfo{2},messageInfo{4},messageInfo{3},messageInfo{5},messageInfo{7},messageInfo{6});
            case {'fminusub','sfminbx','sfminle'}
                % messageInfo = {'fminunc',firstOrdOpt,tolFunChoice,tolFun}
                basicMsg = sprintf(['\n%sInitial point is a local minimum%s.\n\n',...
                    'Optimization completed because the %ssize of the gradient%s at the initial point \n',...
                    'is less than the %s value of the %sfunction tolerance%s.\n\n%s\n'], ...
                    uncInitPtTag,endLinkTag,gradSizeTag,endLinkTag,messageInfo{3},functionTolTag,endLinkTag,detailTag);
                
                detailedMsg = sprintf(['\nOptimization completed: The final point is the initial point.\n', ...
                    'The %sfirst-order optimality measure%s, %e, is less than\n%soptions.TolFun%s = %e.\n\n', ...
                    'Optimization Metric                                    Options\n', ...
                    'relative first-order optimality = %10.2e  TolFun = %7.0e (%s)\n'],normGradTag,endLinkTag, ...
                    messageInfo{2},tolFunTag,endLinkTag,messageInfo{4},messageInfo{2},messageInfo{4},messageInfo{3});
            case {'trustnleqn','snls'}
                if strcmpi(messageInfo{1},'fsolve')
                    % messageInfo = {'trustnleqn',firstOrdOpt,tolFunChoice,tolFun,F'*F,tolFunChoice,sqrt(TolFun)}
                    basicMsg = sprintf(['\n%sEquation solved at initial point%s.\n\n',...
                        'fsolve completed because the vector of function values at the initial point\n',...
                        'is near zero as measured by the %s value of the %sfunction tolerance%s, and\n',...
                        'the %sproblem appears regular%s as measured by the gradient.\n\n%s\n'], ...
                        eqSolvInitTag,endLinkTag,messageInfo{3},funcTolFsolveTag,endLinkTag,regProbTag,endLinkTag, ...
                        detailTag);
                    
                    detailedMsg = sprintf(['\nEquation solved. The final point is the initial point.\n', ...
                        'The sum of squared function values, r = %e, is less than ',...
                        'sqrt(%soptions.TolFun%s) = %e.\nThe relative norm of the ',...
                        'gradient of r, %e, is less than options.TolFun = %e.\n\n', ...
                        'Optimization Metric                                        Options\n', ...
                        'relative norm(grad r) = %10.2e                TolFun = %7.0e (%s)\n', ...
                        'r = %10.2e                             sqrt(TolFun) = %8.1e (%s)\n'],messageInfo{5}, ...
                        tolFunFsolveTag,endLinkTag,messageInfo{7},messageInfo{2},messageInfo{4},messageInfo{2}, ...
                        messageInfo{4},messageInfo{3},messageInfo{5},messageInfo{7},messageInfo{6});
                else % caller is lsqnonlin/lsqcurvefit
                    % messageInfo = {'lsqnonlin',firstOrdOpt,tolFunChoice,tolFun}
                    basicMsg = sprintf(['\n%sInitial point is a local minimum%s.\n\n',...
                        'Optimization completed because the %ssize of the gradient%s at the initial point \n',...
                        'is less than the %s value of the %sfunction tolerance%s.\n\n%s\n'], ...
                        lsqInitPtTag,endLinkTag,lsqGradSizeTag,endLinkTag,messageInfo{3},functionTolLSQTag,endLinkTag,detailTag);
                    
                    detailedMsg = sprintf(['\nOptimization completed: The final point is the initial point.\n', ...
                        'The %sfirst-order optimality measure%s, %e, is less than\n%soptions.TolFun%s = %e.\n\n', ...
                        'Optimization Metric                                   Options\n', ...
                        'relative first-order optimality = %10.2e         TolFun = %7.0e (%s)\n'],lsqNormGradTag,endLinkTag, ...
                        messageInfo{2},tolFunLSQTag,endLinkTag,messageInfo{4},messageInfo{2},messageInfo{4},messageInfo{3});
                end
            case 'levenbergMarquardt'
                if strcmpi(messageInfo{1},'fsolve')
                    % messageInfo = {'fsolve',firstOrdOpt,tolFunChoice,1e-4*tolFun,F'*F,tolFunChoice,sqrt(TolFun)}
                    basicMsg = sprintf(['\n%sEquation solved at initial point%s.\n\n',...
                        '%s completed because the vector of function values at the initial\npoint is near ',...
                        'zero as measured by the %s value of the %sfunction tolerance%s,\nand ',...
                        'the %sproblem appears regular%s as measured by the gradient.\n\n%s\n'], ...
                        eqSolvInitTag,endLinkTag,messageInfo{1},messageInfo{3},funcTolFsolveTag,endLinkTag, ...
                        regProbTag,endLinkTag,detailTag);
                    
                    detailedMsg = sprintf(['\nEquation solved. The final point is the initial point. The sum ', ...
                        'of squared function values,\nr = %e, is less than sqrt(%soptions.TolFun%s) = %e. ', ...
                        'The relative norm\nof the gradient of r, %e, is less than 1e-4*options.TolFun = %e.\n\n', ...
                        'Optimization Metric                                        Options\n', ...
                        'relative norm(grad r) = %10.2e           1e-4*TolFun = %7.0e (%s)\n', ...
                        'r = %10.2e                             sqrt(TolFun) = %8.1e (%s)\n'],messageInfo{5}, ...
                        tolFunFsolveTag,endLinkTag,messageInfo{7},messageInfo{2},messageInfo{4},messageInfo{2}, ...
                        messageInfo{4},messageInfo{3},messageInfo{5},messageInfo{7},messageInfo{6});
                else % Caller is lsqnonlin/lsqcurvefit
                    % messageInfo = {'lsq*',firstOrdOpt,tolFunChoice,tolFun}
                    basicMsg = sprintf(['\n%sInitial point is a local minimum%s.\n\n',...
                        'Optimization completed because the %ssize of the gradient%s at the initial point\n', ...
                        'is less than the %s value of the %sfunction tolerance%s.\n\n%s\n'], ...
                        lsqInitPtTag,endLinkTag,lsqGradSizeTag,endLinkTag,messageInfo{3},functionTolLSQTag,endLinkTag,detailTag);
                    
                    detailedMsg = sprintf(['\nOptimization completed: The final point is the initial point.\nThe ', ...
                        '%sfirst-order optimality measure%s, %e, is less than\n1e-4*%soptions.TolFun%s = %e.\n\n', ...
                        'Optimization Metric                                      Options\n', ...
                        'relative norm(gradient) = %10.2e      1e-4*TolFun = %7.0e (%s)\n'],lsqNormGradTag,endLinkTag, ...
                        messageInfo{2},tolFunLSQTag,endLinkTag,messageInfo{4},messageInfo{2},messageInfo{4},messageInfo{3});
                end
        end % switch(caller) - exitflag 100
    case optimal % exitflag = 1
        switch caller
            case 'nlconst'
                %messageInfo ={'fmincon',firstordopt,tolFunChoice,tolFun,maxConstr,tolConChoice,tolCon}
                basicMsg = sprintf(['\n%sLocal minimum found that satisfies the constraints%s.\n\n',...
                    'Optimization completed because the objective function is non-decreasing ', ...
                    'in \n%sfeasible directions%s, to within the %s value of the %sfunction tolerance%s,\n', ...
                    'and constraints were satisfied to within the %s value of the %sconstraint tolerance%s.\n\n%s\n'], ...
                    conLocalOptTag,endLinkTag,feasDirTag,endLinkTag,messageInfo{3},functionTolTag,endLinkTag,messageInfo{6}, ...
                    constrTolTag,endLinkTag,detailTag);
                
                detailedMsg = sprintf(['\nOptimization completed: The %sfirst-order optimality measure%s, %e, ', ...
                    'is less\nthan %soptions.TolFun%s = %e, and the maximum constraint violation, %e,\nis less ', ...
                    'than %soptions.TolCon%s = %e.\n\n', ...
                    'Optimization Metric                                                 Options\n', ...
                    'first-order optimality = %10.2e                        TolFun = %7.0e (%s)\n', ...
                    'max(constraint violation) = %10.2e                     TolCon = %7.0e (%s)\n'],firstOrdOptTag,endLinkTag, ...
                    messageInfo{2},tolFunTag,endLinkTag,messageInfo{4},messageInfo{5},tolConTag,endLinkTag,messageInfo{7}, ...
                    messageInfo{2},messageInfo{4},messageInfo{3},messageInfo{5},messageInfo{7},messageInfo{6});
            case {'barrier','sqpLineSearch'}
                %messageInfo ={'fmincon',firstordopt,tolFunChoice,tolFun,maxConstr,tolConChoice,tolCon}
                basicMsg = sprintf(['\n%sLocal minimum found that satisfies the constraints%s.\n\n',...
                    'Optimization completed because the objective function is non-decreasing ', ...
                    'in \n%sfeasible directions%s, to within the %s value of the %sfunction tolerance%s,\n', ...
                    'and constraints were satisfied to within the %s value of the %sconstraint tolerance%s.\n\n%s\n'], ...
                    conLocalOptTag,endLinkTag,feasDirTag,endLinkTag,messageInfo{3},functionTolTag,endLinkTag,messageInfo{6}, ...
                    constrTolTag,endLinkTag,detailTag);
                
                detailedMsg = sprintf(['\nOptimization completed: The relative %sfirst-order optimality measure%s, %e,\n', ...
                    'is less than %soptions.TolFun%s = %e, and the relative maximum constraint\nviolation, %e, is less ', ...
                    'than %soptions.TolCon%s = %e.\n\n', ...
                    'Optimization Metric                                         Options\n', ...
                    'relative first-order optimality = %10.2e       TolFun = %7.0e (%s)\n', ...
                    'relative max(constraint violation) = %10.2e    TolCon = %7.0e (%s)\n'],firstOrdOptTag,endLinkTag, ...
                    messageInfo{2},tolFunTag,endLinkTag,messageInfo{4},messageInfo{5},tolConTag,endLinkTag,messageInfo{7}, ...
                    messageInfo{2},messageInfo{4},messageInfo{3},messageInfo{5},messageInfo{7},messageInfo{6});
            case {'sfminbx','sfminle'}
                %messageInfo = {'fminunc',normGrad,tolFunChoice,tolFun}
                % Create messages for display
                basicMsg = sprintf(['\n%sLocal minimum found%s.\n\n',...
                    'Optimization completed because the %ssize of the gradient%s is less than\n',...
                    'the %s value of the %sfunction tolerance%s.\n\n%s\n'], ...
                    uncLocalOptTag,endLinkTag,gradSizeTag,endLinkTag,messageInfo{3},functionTolTag,endLinkTag,detailTag);
                
                detailedMsg = sprintf(['\nOptimization completed: The %sfirst-order optimality measure%s', ...
                    ', %e, \nis less than %soptions.TolFun%s = %e, and no negative/zero curvature is\n', ...
                    'detected in the trust-region model.\n\n', ...
                    'Optimization Metric                                       Options\n', ...
                    'relative first-order optimality = %10.2e     TolFun = %7.0e (%s)\n'],normGradTag,endLinkTag, ...
                    messageInfo{2},tolFunTag,endLinkTag,messageInfo{4},messageInfo{2},messageInfo{4},messageInfo{3});
            case 'fminusub'
                %messageInfo = {'fminunc',normGrad,tolFunChoice,tolFun}
                % Create messages for display
                basicMsg = sprintf(['\n%sLocal minimum found%s.\n\n',...
                    'Optimization completed because the %ssize of the gradient%s is less than\n',...
                    'the %s value of the %sfunction tolerance%s.\n\n%s\n'], ...
                    uncLocalOptTag,endLinkTag,gradSizeTag,endLinkTag,messageInfo{3},functionTolTag,endLinkTag,detailTag);
                
                detailedMsg = sprintf(['\nOptimization completed: The %sfirst-order optimality measure%s', ...
                    ', %e, is less \nthan %soptions.TolFun%s = %e.\n\n', ...
                    'Optimization Metric                                            Options\n', ...
                    'relative norm(gradient) = %10.2e                  TolFun = %7.0e (%s)\n'],normGradTag,endLinkTag, ...
                    messageInfo{2},tolFunTag,endLinkTag,messageInfo{4},messageInfo{2},messageInfo{4},messageInfo{3});
            case {'snls','trustnleqn'}
                if strcmpi(messageInfo{1},'fsolve')
                    % messageInfo = {'fsolve',firstOrdOpt,tolFunChoice,tolFun,F'*F,tolFunChoice,sqrt(TolFun)}
                    basicMsg = sprintf(['\n%sEquation solved%s.\n\n',...
                        'fsolve completed because the vector of function values is near zero\n',...
                        'as measured by the %s value of the %sfunction tolerance%s, and\n',...
                        'the %sproblem appears regular%s as measured by the gradient.\n\n%s\n'], ...
                        eqSolvedTag,endLinkTag,messageInfo{3},funcTolFsolveTag,endLinkTag,regProbTag,endLinkTag, ...
                        detailTag);
                    
                    detailedMsg = sprintf(['\nEquation solved. The sum of squared function values, r = %e, ', ...
                        'is less than\nsqrt(%soptions.TolFun%s) = %e. The relative norm of the ', ...
                        'gradient of r, %e,\nis less than options.TolFun = %e.\n\n',...
                        'Optimization Metric                                             Options\n', ...
                        'relative norm(grad r) = %10.2e                     TolFun = %7.0e (%s)\n', ...
                        'r = %10.2e                                  sqrt(TolFun) = %8.1e (%s)\n'], ...
                        messageInfo{5},tolFunFsolveTag,endLinkTag,messageInfo{7},messageInfo{2},messageInfo{4}, ...
                        messageInfo{2},messageInfo{4},messageInfo{3},messageInfo{5},messageInfo{7},messageInfo{6});
                else % Caller is lsqnonlin or lsqcurvefit
                    % messageInfo = {'lsq*',firstOrdOpt,tolFunChoice,tolFun}
                    basicMsg = sprintf(['\n%sLocal minimum found%s.\n\n',...
                        'Optimization completed because the %ssize of the gradient%s is less than\n',...
                        'the %s value of the %sfunction tolerance%s.\n\n%s\n'], ...
                        lsqLocalOptTag,endLinkTag,lsqGradSizeTag,endLinkTag,messageInfo{3},functionTolLSQTag,endLinkTag,detailTag);
                    
                    detailedMsg = sprintf(['\nOptimization completed: The %sfirst-order optimality measure%s, %e,\n', ...
                        'is less than %soptions.TolFun%s = %e.\n\n', ...
                        'Optimization Metric                                       Options\n', ...
                        'relative first-order optimality = %10.2e     TolFun = %7.0e (%s)\n'],lsqNormGradTag,endLinkTag, ...
                        messageInfo{2},tolFunLSQTag,endLinkTag,messageInfo{4},messageInfo{2},messageInfo{4},messageInfo{3});
                end
            case 'levenbergMarquardt'
                if strcmpi(messageInfo{1},'fsolve')
                    % messageInfo = {'fsolve',firstOrdOpt,tolFunChoice,tolFun,F'*F,tolFunChoice,sqrt(TolFun)}
                    basicMsg = sprintf(['\n%sEquation solved%s.\n\n',...
                        '%s completed because the vector of function values is near zero\n',...
                        'as measured by the %s value of the %sfunction tolerance%s, and\n',...
                        'the %sproblem appears regular%s as measured by the gradient.\n\n%s\n'], ...
                        eqSolvedTag,endLinkTag,messageInfo{1},messageInfo{3},funcTolFsolveTag,endLinkTag, ...
                        regProbTag,endLinkTag,detailTag);
                    
                    detailedMsg = sprintf(['\nEquation solved. The sum of squared function values, r = %e, ', ...
                        'is less\nthan sqrt(%soptions.TolFun%s) = %e. The relative norm of the ', ...
                        'gradient of\nr, %e, is less than 1e-4*options.TolFun = %e.\n\n',...
                        'Optimization Metric                                        Options\n', ...
                        'relative norm(grad r) = %10.2e           1e-4*TolFun = %7.0e (%s)\n', ...
                        'r = %10.2e                             sqrt(TolFun) = %8.1e (%s)\n'], ...
                        messageInfo{5},tolFunFsolveTag,endLinkTag,messageInfo{7},messageInfo{2},messageInfo{4}, ...
                        messageInfo{2},messageInfo{4},messageInfo{3},messageInfo{5},messageInfo{7},messageInfo{6});
                else % Caller is lsqnonlin/lsqcurvefit
                    % messageInfo = {'lsq*',firstOrdOpt,tolFunChoice,tolFun}
                    basicMsg = sprintf(['\n%sLocal minimum found%s.\n\n',...
                        'Optimization completed because the %ssize of the gradient%s is less than\n',...
                        'the %s value of the %sfunction tolerance%s.\n\n%s\n'], ...
                        lsqLocalOptTag,endLinkTag,lsqGradSizeTag,endLinkTag,messageInfo{3},functionTolLSQTag,endLinkTag,detailTag);
                    
                    detailedMsg = sprintf(['\nOptimization completed: The %sfirst-order optimality measure%s, %e,\n', ...
                        'is less than 1e-4*%soptions.TolFun%s = %e.\n\n', ...
                        'Optimization Metric                                       Options\n', ...
                        'relative norm(gradient) = %10.2e        1e-4*TolFun = %7.0e (%s)\n'],lsqNormGradTag,endLinkTag, ...
                        messageInfo{2},tolFunLSQTag,endLinkTag,messageInfo{4},messageInfo{2},messageInfo{4},messageInfo{3});
                end
        end % switch(caller) - exitflag 1
    case deltaX % exitflag = 2
        switch caller
            case {'barrier','sqpLineSearch'}
                % Create messages for display
                % messageInfo = {'fmincon',normStep,tolXchoice,tolX,maxConstr,tolConChoice,tolCon}
                basicMsg = sprintf(['\n%sLocal minimum possible. Constraints satisfied%s.\n\n',...
                    '%s stopped because the %ssize of the current step%s is less than\n',...
                    'the %s value of the %sstep size tolerance%s and constraints were \nsatisfied to ',...
                    'within the %s value of the %sconstraint tolerance%s.\n\n%s\n'], ...
                    conPossMinTag,endLinkTag,messageInfo{1},conNormStepTag,endLinkTag,messageInfo{3}, ...
                    stepSizeTolTag,endLinkTag,messageInfo{6},constrTolTag,endLinkTag,detailTag);
                
                detailedMsg = sprintf(['\nOptimization stopped because the %srelative changes in all elements of x%s', ...
                    ' are\nless than %soptions.TolX%s = %e, and the relative maximum constraint\n', ...
                    'violation, %e, is less than %soptions.TolCon%s = %e.\n\n', ...
                    'Optimization Metric                                         Options\n', ...
                    'max(abs(delta_x./x)) = %10.2e                    TolX = %7.0e (%s)\n' ,...
                    'relative max(constraint violation) = %10.2e    TolCon = %7.0e (%s)\n'],conNormStepTag,endLinkTag, ...
                    tolXTag,endLinkTag,messageInfo{4},messageInfo{5},tolConTag,endLinkTag,messageInfo{7}, ...
                    messageInfo{2},messageInfo{4},messageInfo{3},messageInfo{5},messageInfo{7},messageInfo{6});
            case {'fminusub','sfminbx','sfminle'}
                %messageInfo = {'fminunc',norm(deltaX),tolXChoice,tolX}
                % Create messages for display
                basicMsg = sprintf(['\n%sLocal minimum possible%s.\n\n',...
                    '%s stopped because the %ssize of the current step%s is less than\n',...
                    'the %s value of the %sstep size tolerance%s.\n\n%s\n'], ...
                    uncPossMinTag,endLinkTag,messageInfo{1},normStepTag,endLinkTag,messageInfo{3},stepSizeTolTag,endLinkTag,detailTag);
                
                detailedMsg = sprintf(['\nOptimization stopped because the %snorm of the current step%s', ...
                    ', %e, is\nless than %soptions.TolX%s = %e.\n\n', ...
                    'Optimization Metric                                    Options\n', ...
                    'relative norm(step) = %10.2e                TolX = %7.0e (%s)\n'], ...
                    normStepTag,endLinkTag,messageInfo{2},tolXTag,endLinkTag, ...
                    messageInfo{4},messageInfo{2},messageInfo{4},messageInfo{3});
            case 'snls' 
                if strcmpi(messageInfo{1},'fsolve')
                    %messageInfo = {'fsolve',norm(deltaX),tolXChoice,tolX,F'*F,tolFunChoice,sqrt(tolFun)}
                    % Create messages for display
                    basicMsg = sprintf(['\n%sEquation solved, fsolve stalled%s.\n\n',...
                        '%s stopped because the %ssize of the current step%s is less than ',...
                        'the %s\nvalue of the %sstep size tolerance%s and the vector of ', ...
                        'function values\nis near zero as measured by the %s value of the ',...
                        '%sfunction tolerance%s.\n\n%s\n'],eqSolveSingTag,endLinkTag,messageInfo{1}, ...
                        normStepTag,endLinkTag,messageInfo{3},stepSizeTolTag,endLinkTag,messageInfo{6}, ...
                        funcTolFsolveTag,endLinkTag,detailTag);
                    
                    detailedMsg = sprintf(['\n%s stopped because the %snorm of the current step%s, %e, is ', ...
                        'less than\n%soptions.TolX%s = %e. The sum of squared function values, r = %e,\n',...
                        'is less than sqrt(%soptions.TolFun%s) = %e.\n\n', ...
                        'Optimization Metric                                      Options\n', ...
                        'norm(step) = %10.2e                           TolX = %7.0e (%s)\n', ...
                        'r = %10.2e                           sqrt(TolFun) = %8.1e (%s)\n'], ... 
                        messageInfo{1},normStepTag,endLinkTag,messageInfo{2},tolXTag,endLinkTag, ...
                        messageInfo{4},messageInfo{5},tolFunFsolveTag,endLinkTag,messageInfo{7},messageInfo{2}, ...
                        messageInfo{4},messageInfo{3},messageInfo{5},messageInfo{7},messageInfo{6});
                else % Caller is lsqnonlin/lsqcurvefit
                    %messageInfo = {'lsqnonlin',norm(deltaX),tolXChoice,tolX}
                    basicMsg = sprintf(['\n%sLocal minimum possible%s.\n\n',...
                        '%s stopped because the %ssize of the current step%s is less than\n',...
                        'the %s value of the %sstep size tolerance%s.\n\n%s\n'], ...
                        lsqPossMinTag,endLinkTag,messageInfo{1},normStepTag,endLinkTag,messageInfo{3}, ...
                        stepSizeTolTag,endLinkTag,detailTag);
                    
                    detailedMsg = sprintf(['\nOptimization stopped because the %snorm of the current step%s', ...
                        ', %e,\nis less than %soptions.TolX%s = %e.\n\n', ...
                        'Optimization Metric                                 Options\n', ...
                        'norm(step) = %10.2e                      TolX = %7.0e (%s)\n'], ...
                        normStepTag,endLinkTag,messageInfo{2},tolXTag,endLinkTag, ...
                        messageInfo{4},messageInfo{2},messageInfo{4},messageInfo{3});
                end
            case 'trustnleqn'
                %messageInfo = {'fsolve',norm(deltaX),tolXChoice,max(tolX^2,eps),F'*F,tolFunChoice,sqrt(tolFun)}
                % Create messages for display
                basicMsg = sprintf(['\n%sEquation solved, fsolve stalled%s.\n\n',...
                    '%s stopped because the relative %ssize of the current step%s is less than ',...
                    'the\n%s value of the %sstep size tolerance%s squared and the vector of ', ...
                    'function values\nis near zero as measured by the %s value of the ',...
                    '%sfunction tolerance%s.\n\n%s\n'],eqSolveSingTag,endLinkTag,messageInfo{1}, ...
                    normStepTag,endLinkTag,messageInfo{3},stepSizeTolTag,endLinkTag,messageInfo{6}, ...
                    funcTolFsolveTag,endLinkTag,detailTag);
                
                detailedMsg = sprintf(['\n%s stopped because the relative %snorm of the current step%s, ', ...
                    '%e, is less than \nmax(%soptions.TolX%s^2,eps) = %e. The sum of squared function ',...
                    'values, r = %e,\nis less than sqrt(%soptions.TolFun%s) = %e.\n\n', ...
                    'Optimization Metric                                              Options\n', ...
                    'relative norm(step) = %10.2e               max(TolX^2,eps) = %7.0e (%s)\n', ...
                    'r = %10.2e                                   sqrt(TolFun) = %8.1e (%s)\n'], ...
                    messageInfo{1},normStepTag,endLinkTag,messageInfo{2},tolXTag,endLinkTag, ...
                    messageInfo{4},messageInfo{5},tolFunFsolveTag,endLinkTag,messageInfo{7},messageInfo{2}, ...
                    messageInfo{4},messageInfo{3},messageInfo{5},messageInfo{7},messageInfo{6});
        end % switch(caller) - exitflag 2
    case undefGrads % exitflag = 26
        % Only caller is sqpLineSearch, do not break out by algorithm
        % messageInfo = {'fmincon',maxConstr,tolConChoice,tolCon}
        basicMsg = sprintf(['\n%sLocal minimum possible. Constraints satisfied%s.\n\n',...
            '%s stopped because the %sgradient calculation is undefined%s. Constraints\n',...
            'were satisfied to within the %s value of the %sconstraint tolerance%s.\n\n%s\n'], ...
            conPossMinTag,endLinkTag,messageInfo{1},gradCalcFailTag,endLinkTag,messageInfo{3}, ...
            constrTolTag,endLinkTag,detailTag);
        
        detailedMsg = sprintf(['\nOptimization stopped because the objective or constraint ',...
            '%sgradient calculation is undefined%s\nat the current point and the relative maximum ', ...
            'constraint violation, %e, is \nless than %soptions.TolCon%s = %e.\n\n', ...
            'Optimization Metric                                             Options\n', ...
            'relative max(constraint violation) = %10.2e        TolCon = %7.0e (%s)\n'], ...
            gradCalcFailTag,endLinkTag,messageInfo{2},tolConTag,endLinkTag,messageInfo{4}, ...
            messageInfo{2},messageInfo{4},messageInfo{3});
    case deltaF % exitflag = 3
        switch caller
            case {'sfminbx','sfminle'}
                % messageInfo = {'fmincon',relnorm(deltaF),tolFunChoice,tolFun}
                basicMsg = sprintf(['\n%sLocal minimum possible%s.\n\n',...
                    '%s stopped because the final change in function value relative to \nits ', ...
                    'initial value is less than the %s value of the %sfunction tolerance%s.\n\n%s\n'], ...
                    uncPossMinTag,endLinkTag,messageInfo{1},messageInfo{3},functionTolTag,endLinkTag,detailTag);
                
                detailedMsg = sprintf(['\nOptimization stopped because the relative objective ', ...
                    'function value is changing\nby less than %soptions.TolFun%s = %e.\n\n', ...
                    'Optimization Metric                                         Options\n', ...
                    'relative change objective = %10.2e             TolFun = %7.0e (%s)\n'], ...
                    tolFunTag,endLinkTag,messageInfo{4},messageInfo{2},messageInfo{4},messageInfo{3});
            case {'snls','levenbergMarquardt'}
                if strcmpi(messageInfo{1},'fsolve')
                    % messageInfo = {'fsolve',relnorm(deltaF),tolFunChoice,tolFun,F'*F,tolFunChoice,sqrt(tolFun)}
                    basicMsg = sprintf(['\n%sEquation solved, inaccuracy possible%s.\n\n',...
                        'The vector of function values is near zero, as measured by the %s value\nof the ',...
                        '%sfunction tolerance%s. However, the %slast step was ineffective%s.\n\n%s\n'],eqSolvedInaccTag, ...
                        endLinkTag,messageInfo{6},funcTolFsolveTag,endLinkTag,ineffectiveStepTag,endLinkTag,detailTag);
                    
                    detailedMsg = sprintf(['\n%s stopped because the sum of squared function values, r, changed ', ...
                        'by %e\nrelative to its initial value; this is less than %soptions.TolFun%s = %e.\n', ...
                        'r = %e, is less than sqrt(options.TolFun) = %e.\n\n' ...
                        'Optimization Metric                                     Options\n', ...
                        'relative change r = %10.2e                     TolFun = %7.0e (%s)\n', ...
                        'r = %10.2e                              sqrt(TolFun) = %8.1e (%s)\n'],messageInfo{1}, ...
                        messageInfo{2},tolFunFsolveTag,endLinkTag,messageInfo{4},messageInfo{5},messageInfo{7}, ...
                        messageInfo{2},messageInfo{4},messageInfo{3},messageInfo{5},messageInfo{7},messageInfo{6});
                else % caller is lsqnonlin/lsqcuvefit
                    % messageInfo = {'lsqnonlin',relnorm(deltaF),tolFunChoice,tolFun}
                    basicMsg = sprintf(['\n%sLocal minimum possible%s.\n\n',...
                        '%s stopped because the final change in the sum of squares relative to \nits ', ...
                        'initial value is less than the %s value of the %sfunction tolerance%s.\n\n%s\n'], ...
                        lsqPossMinTag,endLinkTag,messageInfo{1},messageInfo{3},functionTolLSQTag,endLinkTag,detailTag);
                    
                    detailedMsg = sprintf(['\nOptimization stopped because the relative sum of squares (r) is ', ...
                        'changing\nby less than %soptions.TolFun%s = %e.\n\n', ...
                        'Optimization Metric                                  Options\n', ...
                        'relative change r = %10.2e              TolFun = %7.0e (%s)\n'], ...
                        tolFunLSQTag,endLinkTag,messageInfo{4},messageInfo{2},messageInfo{4},messageInfo{3});
                end
            case 'trustnleqn'
                % messageInfo = {'fsolve',relnorm(deltaF),tolFunChoice,tolFun,F'*F,tolFunChoice,sqrt(tolFun)}
                basicMsg = sprintf(['\n%sEquation solved, inaccuracy possible%s.\n\n',...
                    'The vector of function values is near zero, as measured by the %s value\nof the ',...
                    '%sfunction tolerance%s. However, the %slast step was ineffective%s.\n\n%s\n'],eqSolvedInaccTag, ...
                    endLinkTag,messageInfo{6},funcTolFsolveTag,endLinkTag,ineffectiveStepTag,endLinkTag,detailTag);
                
                detailedMsg = sprintf(['\n%s stopped because the sum of squared function values, r, changed ', ...
                    'by %e\nrelative to its initial value; this is less than max(%soptions.TolFun%s^2,eps) ', ...
                    '= %e.\nr = %e, is less than sqrt(options.TolFun) = %e.\n\n' ...
                    'Optimization Metric                                                Options\n', ...
                    'relative change r = %10.2e                 max(TolFun^2,eps) = %7.0e (%s)\n', ...
                    'r = %10.2e                                     sqrt(TolFun) = %8.1e (%s)\n'], ...
                    messageInfo{1},messageInfo{2},tolFunFsolveTag,endLinkTag,messageInfo{4},messageInfo{5},messageInfo{7}, ...
                    messageInfo{2},messageInfo{4},messageInfo{3},messageInfo{5},messageInfo{7},messageInfo{6});
        end % switch(caller) - exitflag 3
    case smallSearchDir % exitflag = 4
        switch caller
            case 'nlconst'
                % messageInfo = {'fmincon',normSD,tolXchoice,tolX,maxConstr,tolConChoice,tolCon}
                basicMsg = sprintf(['\n%sLocal minimum possible. Constraints satisfied%s.\n\n',...
                    '%s stopped because the %ssize of the current search direction%s is less than\n',...
                    'twice the %s value of the %sstep size tolerance%s and constraints were \nsatisfied to ',...
                    'within the %s value of the %sconstraint tolerance%s.\n\n%s\n'], ...
                    conPossMinTag,endLinkTag,messageInfo{1},normSearchDirTag,endLinkTag,messageInfo{3}, ...
                    stepSizeTolTag,endLinkTag,messageInfo{6},constrTolTag,endLinkTag,detailTag);
                
                detailedMsg = sprintf(['\nOptimization stopped because the %snorm of the current search direction%s', ...
                    ', %e,\nis less than 2*%soptions.TolX%s = %e, and the maximum ', ...
                    'constraint \nviolation, %e, is less than %soptions.TolCon%s = %e.\n\n', ...
                    'Optimization Metric                                               Options\n', ...
                    'norm(search direction) = %10.2e                        TolX = %7.0e (%s)\n' ,...
                    'max(constraint violation)  = %10.2e                  TolCon = %7.0e (%s)\n'],normSearchDirTag, ...
                    endLinkTag,messageInfo{2},tolXTag,endLinkTag,messageInfo{4},messageInfo{5},tolConTag,endLinkTag, ...
                    messageInfo{7},messageInfo{2},messageInfo{4},messageInfo{3},messageInfo{5},messageInfo{7},messageInfo{6});
                
            case 'levenbergMarquardt'
                if strcmpi(messageInfo{1},'fsolve')
                    %messageInfo = {'fsolve',norm(deltaX),tolXChoice,tolX,F'*F,tolFunChoice,sqrt(tolFun)}
                    basicMsg = sprintf(['\n%sEquation solved, fsolve stalled%s.\n\n',...
                        '%s stopped because the relative %ssize of the current step%s is less than ',...
                        'the\n%s value of the %sstep size tolerance%s and the vector of ', ...
                        'function values\nis near zero as measured by the %s value of the ',...
                        '%sfunction tolerance%s.\n\n%s\n'],eqSolveSingTag,endLinkTag,messageInfo{1}, ...
                        normStepTag,endLinkTag,messageInfo{3},stepSizeTolTag,endLinkTag,messageInfo{6}, ...
                        funcTolFsolveTag,endLinkTag,detailTag);
                    
                    detailedMsg = sprintf(['\n%s stopped because the relative %snorm of the current step%s, ', ...
                        '%e, is less\nthan %soptions.TolX%s = %e. The sum of squared function values, ',...
                        'r = %e,\nis less than sqrt(%soptions.TolFun%s) = %e.\n\n', ...
                        'Optimization Metric                                         Options\n', ...
                        'relative norm(step) = %10.2e                     TolX = %7.0e (%s)\n', ...
                        'r = %10.2e                              sqrt(TolFun) = %8.1e (%s)\n'], ...
                        messageInfo{1},normStepTag,endLinkTag,messageInfo{2},tolXTag,endLinkTag, ...
                        messageInfo{4},messageInfo{5},tolFunFsolveTag,endLinkTag,messageInfo{7},messageInfo{2}, ...
                        messageInfo{4},messageInfo{3},messageInfo{5},messageInfo{7},messageInfo{6});
                else % Caller is lsqnonlin/lsqcurvefit
                    %messageInfo = {'lsqnonlin',norm(deltaX),tolXChoice,tolX}
                    % Create messages for display
                    basicMsg = sprintf(['\n%sLocal minimum possible%s.\n\n',...
                        '%s stopped because the relative %ssize of the current step%s is less than\n',...
                        'the %s value of the %sstep size tolerance%s.\n\n%s\n'], ...
                        lsqPossMinTag,endLinkTag,messageInfo{1},normStepTag,endLinkTag,messageInfo{3}, ...
                        stepSizeTolTag,endLinkTag,detailTag);
                    
                    detailedMsg = sprintf(['\nOptimization stopped because the relative %snorm of the current step%s', ...
                        ', %e,\nis less than %soptions.TolX%s = %e.\n\n', ...
                        'Optimization Metric                                     Options\n', ...
                        'relative norm(step) = %10.2e                 TolX = %7.0e (%s)\n'], ...
                        normStepTag,endLinkTag,messageInfo{2},tolXTag,endLinkTag, ...
                        messageInfo{4},messageInfo{2},messageInfo{4},messageInfo{3});
                end
        end
    case dirDeriv % exitflag = 5
        switch caller
            case 'nlconst'
                % Create messages for display
                % messageInfo = {'fmincon',abs(alpha*dirDeriv),tolFunChoice,tolFun,maxConstr,tolConChoice,tolCon}
                basicMsg = sprintf(['\n%sLocal minimum possible. Constraints satisfied%s.\n\n',...
                    '%s stopped because the %spredicted change in the objective function%s\n', ...
                    'is less than the %s value of the %sfunction tolerance%s and constraints \nwere satisfied to ',...
                    'within the %s value of the %sconstraint tolerance%s.\n\n%s\n'], ...
                    conPossMinTag,endLinkTag,messageInfo{1},dirDerivTag,endLinkTag,messageInfo{3}, ...
                    functionTolTag,endLinkTag,messageInfo{6},constrTolTag,endLinkTag,detailTag);
                
                detailedMsg = sprintf(['\nOptimization stopped because the %spredicted change in the objective function%s', ...
                    ',\n%e, is less than %soptions.TolFun%s = %e, and the maximum constraint\n', ...
                    'violation, %e, is less than %soptions.TolCon%s = %e.\n\n', ...
                    'Optimization Metric                                                 Options\n',...
                    'abs(steplength*directional derivative) = %10.2e        TolFun = %7.0e (%s)\n' ,...
                    'max(constraint violation) = %10.2e                     TolCon = %7.0e (%s)\n'],dirDerivTag, ...
                    endLinkTag,messageInfo{2},tolFunTag,endLinkTag,messageInfo{4},messageInfo{5},tolConTag,endLinkTag, ...
                    messageInfo{7},messageInfo{2},messageInfo{4},messageInfo{3},messageInfo{5},messageInfo{7},messageInfo{6});
            case 'fminusub'
                %messageInfo = {'fminunc',abs(alpha*dirDeriv),tolFunChoice,tolFun}
                % Create messages for display
                basicMsg = sprintf(['\n%sLocal minimum possible%s.\n\n',...
                    '%s stopped because it cannot decrease the objective function\n', ...
                    'along the current %ssearch direction%s.\n\n%s\n'], ...
                    uncPossMinTag,endLinkTag,messageInfo{1},searchDirTag,endLinkTag,detailTag);
                
                detailedMsg = sprintf(['\nOptimization stopped because the objective function cannot be decreased ', ...
                    'in the \ncurrent %ssearch direction%s. Either the %spredicted change in the objective function%s,\n', ...
                    'or the %sline search interval%s is less than eps.'],searchDirTag,endLinkTag, ...
                    dirDerivTag,endLinkTag,lsIntervalTag,endLinkTag);
        end % switch caller - exitflag 5
    case maxFunEval % exitflag = 0
        % Create messages for display: messageInfo = {'topLevelFcn',[],maxFunEvalsChoice,maxFunEvals}
        basicMsg = sprintf(['\n%sSolver stopped prematurely%s.\n\n', ...
            '%s stopped because it exceeded the function evaluation limit,\n',...
            '%soptions.MaxFunEvals%s = %i (the %s value).\n'],prematureStopTag,endLinkTag,messageInfo{1},...
            maxFunEvalTag,endLinkTag,messageInfo{4},messageInfo{3});
        % Force detailedExitMsg to false so that basicMsg will always print, since there is no detailedMsg.
	detailedExitMsg = false;
    case maxIter % exitflag = 10
        % Create messages for display: messageInfo = {'topLevelFcn',[],maxIterChoice,maxIter}
        basicMsg = sprintf(['\n%sSolver stopped prematurely%s.\n\n', ...
            '%s stopped because it exceeded the iteration limit,\n',...
            '%soptions.MaxIter%s = %i (the %s value).\n'],prematureStopTag,endLinkTag,messageInfo{1}, ...
            maxIterTag,endLinkTag,messageInfo{4},messageInfo{3});
        % Force detailedExitMsg to false so that basicMsg will always print, since there is no detailedMsg.
        detailedExitMsg = false;
    case outputFcn % exitflag = -1
        % Create messages for display: messageInfo = {'topLevelFcn'}
        basicMsg = sprintf('\n%s stopped by the %soutput or plot function%s.',...
            messageInfo{1},outputFcnTag,endLinkTag);
        % Force detailedExitMsg to false so that basicMsg will always print, since there is no detailedMsg.        
        detailedExitMsg = false;
    case infeasSQP % exitflag = -20
        % Create messages for display - caller is nlconst
        % messageInfo = {'fmincon',[],maxSQPIterChoice,maxSQPIter,maxConstr,tolConChoice,tolCon}
        basicMsg = sprintf(['\n%sNo feasible solution found%s.\n\n',...
            '%s stopped because it was unable to find a point locally that satisfies\n',...
            'the constraints within the %s value of the %sconstraint tolerance%s.\n\n%s\n'], ...
            inFeasTag,endLinkTag,messageInfo{1},messageInfo{6},constrTolTag,endLinkTag,detailTag);
        
        detailedMsg = sprintf(['\nOptimization stopped because the maximum number of iterations ', ...
            'of the\nquadratic programming subproblem, %soptions.MaxSQPIter%s = %i, was\nreached ', ...
            'but the maximum constraint violation, %e, exceeds\n%soptions.TolCon%s = %e.\n\n', ...
            'Optimization Metric                                         Options\n', ...
            'max(constraint violation) = %10.2e            TolCon = %7.0e (%s)\n'], ...
            maxSQPIterTag,endLinkTag,messageInfo{4},messageInfo{5},tolConTag,endLinkTag, ...
            messageInfo{7},messageInfo{5},messageInfo{7},messageInfo{6});
    case infeasStationary % exitflag = -21
        switch caller
            case 'barrier'
                % messageInfo = {'fmincon',maxConstr,tolConChoice,tolCon}
                basicMsg = sprintf(['\n%sNo feasible solution found%s.\n\n',...
                    '%s stopped because it was unable to find a point locally that satisfies\n',...
                    'the constraints within the %s value of the %sconstraint tolerance%s.\n\n%s\n'], ...
                    inFeasTag,endLinkTag,messageInfo{1},messageInfo{3},constrTolTag,endLinkTag,detailTag);
                
                detailedMsg = sprintf(['\nOptimization stopped because the %sconstraint violations ', ...
                    'are locally stationary%s \nbut the relative maximum constraint violation,', ...
                    ' %e, exceeds\n%soptions.TolCon%s = %e.\n\n', ...
                    'Optimization Metric                                         Options\n', ...
                    'relative max(constraint violation) = %10.2e    TolCon = %7.0e (%s)\n'],stationaryConstrTag,endLinkTag, ...
                    messageInfo{2},tolConTag,endLinkTag,messageInfo{4},messageInfo{2},messageInfo{4},messageInfo{3});
            case {'snls','trustnleqn'}
                % messageInfo = {'fsolve',gradNorm,tolFunChoice,tolFun,F'*F,tolFunChoice,sqrt(tolFun)}
                basicMsg = sprintf(['\n%sNo solution found%s.\n\n',...
                    '%s stopped because the %sproblem appears regular%s as measured by the %sgradient%s,\n', ...
                    'but the vector of function values is not near zero as measured by the\n',...
                    '%s value of the %sfunction tolerance%s.\n\n%s\n'], ...
                    noEqSolTag,endLinkTag,messageInfo{1},regProbTag,endLinkTag,lsqGradSizeTag,endLinkTag, ...
                    messageInfo{3},funcTolFsolveTag,endLinkTag,detailTag);
                
                detailedMsg = sprintf(['\n%s stopped because the sum of squared function values, r, has ', ...
                    'gradient with\nrelative norm %e; this is less than %soptions.TolFun%s = %e.\nHowever, ',...
                    'r = %e, exceeds sqrt(options.TolFun) = %e.\n\n', ...
                    'Optimization Metric                                          Options\n', ...
                    'norm(grad r) = %10.2e                           TolFun = %7.0e (%s)\n', ...
                    'r = %10.2e                               sqrt(TolFun) = %8.1e (%s)\n'], ...
                    messageInfo{1},messageInfo{2},tolFunFsolveTag,endLinkTag,messageInfo{4},messageInfo{5},messageInfo{7}, ...
                    messageInfo{2},messageInfo{4},messageInfo{3},messageInfo{5},messageInfo{7},messageInfo{6});
            case 'levenbergMarquardt'
                % messageInfo = {'fsolve',firstOrdOpt,tolFunChoice,tolFun,F'*F,tolFunChoice,sqrt(TolFun)}
                basicMsg = sprintf(['\n%sNo solution found%s.\n\n',...
                    '%s stopped because the %sproblem appears regular%s as measured by the %sgradient%s,\n', ...
                    'but the vector of function values is not near zero as measured by the\n',...
                    '%s value of the %sfunction tolerance%s.\n\n%s\n'], ...
                    noEqSolTag,endLinkTag,messageInfo{1},regProbTag,endLinkTag,lsqGradSizeTag,endLinkTag, ...
                    messageInfo{3},funcTolFsolveTag,endLinkTag,detailTag);
                
                detailedMsg = sprintf(['\n%s stopped because the sum of squared function values, r, has ', ...
                    'gradient with\nrelative norm %e; this is less than 1e-4*%soptions.TolFun%s = %e.\nHowever, ',...
                    'r = %e, exceeds sqrt(options.TolFun) = %e.\n\n', ...
                    'Optimization Metric                                      Options\n', ...
                    'norm(grad r) = %10.2e                  1e-4*TolFun = %7.0e (%s)\n', ...
                    'r = %10.2e                           sqrt(TolFun) = %8.1e (%s)\n'], ...
                    messageInfo{1},messageInfo{2},tolFunFsolveTag,endLinkTag,messageInfo{4},messageInfo{5},messageInfo{7}, ...
                    messageInfo{2},messageInfo{4},messageInfo{3},messageInfo{5},messageInfo{7},messageInfo{6});
        end % switch caller - exitflag -21
    case infeasDeltaX % exitflag = -22
        switch caller
            case {'barrier','sqpLineSearch'}
                % messageInfo = {'fmincon',normStep,tolXchoice,tolX,maxConstr,tolConChoice,tolCon}
                basicMsg = sprintf(['\n%sNo feasible solution found%s.\n\n',...
                    '%s stopped because the %ssize of the current step%s is less than\n',...
                    'the %s value of the %sstep size tolerance%s but constraints were not\nsatisfied to ',...
                    'within the %s value of the %sconstraint tolerance%s.\n\n%s\n'], ...
                    inFeasTag,endLinkTag,messageInfo{1},conNormStepTag,endLinkTag,messageInfo{3}, ...
                    stepSizeTolTag,endLinkTag,messageInfo{6},constrTolTag,endLinkTag,detailTag);
                
                detailedMsg = sprintf(['\nOptimization stopped because the %srelative changes in all elements of x%s', ...
                    ' are\nless than %soptions.TolX%s = %e, but the relative maximum constraint\n', ...
                    'violation, %e, exceeds %soptions.TolCon%s = %e.\n\n', ...
                    'Optimization Metric                                         Options\n', ...
                    'max(abs(delta_x./x)) = %10.2e                    TolX = %7.0e (%s)\n' ,...
                    'relative max(constraint violation) = %10.2e    TolCon = %7.0e (%s)\n'],conNormStepTag,endLinkTag, ...
                    tolXTag,endLinkTag,messageInfo{4},messageInfo{5},tolConTag,endLinkTag,messageInfo{7}, ...
                    messageInfo{2},messageInfo{4},messageInfo{3},messageInfo{5},messageInfo{7},messageInfo{6});              
            case 'trustnleqn'
                %messageInfo = {'fsolve',norm(deltaX),tolXChoice,max(tolX^2,eps),F'*F,tolFunChoice,sqrt(tolFun)}
                basicMsg = sprintf(['\n%sNo solution found%s.\n\n',...
                    '%s stopped because the relative %ssize of the current step%s is less than ',...
                    'the\n%s value of the %sstep size tolerance%s squared, but the vector of ', ...
                    'function values\nis not near zero as measured by the %s value of the ',...
                    '%sfunction tolerance%s.\n\n%s\n'],noEqSolTag,endLinkTag,messageInfo{1}, ...
                    normStepTag,endLinkTag,messageInfo{3},stepSizeTolTag,endLinkTag,messageInfo{6}, ...
                    funcTolFsolveTag,endLinkTag,detailTag);
                
                detailedMsg = sprintf(['\n%s stopped because the relative %snorm of the current step%s, %e, ', ...
                    'is less than\nmax(%soptions.TolX%s^2,eps) = %e. However, the sum of squared function ',...
                    'values,\nr = %e, exceeds sqrt(%soptions.TolFun%s) = %e.\n\n', ...
                    'Optimization Metric                                               Options\n', ...
                    'relative norm(step) = %10.2e                max(TolX^2,eps) = %7.0e (%s)\n', ...
                    'r = %10.2e                                    sqrt(TolFun) = %8.1e (%s)\n'], ...
                    messageInfo{1},normStepTag,endLinkTag,messageInfo{2},tolXTag,endLinkTag, ...
                    messageInfo{4},messageInfo{5},tolFunFsolveTag,endLinkTag,messageInfo{7},messageInfo{2},messageInfo{4}, ...
                    messageInfo{3},messageInfo{5},messageInfo{7},messageInfo{6});
            case 'snls'
                %messageInfo = {'fsolve',norm(deltaX),tolXChoice,tolX,F'*F,tolFunChoice,sqrt(tolFun)}
                basicMsg = sprintf(['\n%sNo solution found%s.\n\n',...
                    '%s stopped because the %ssize of the current step%s is less than ',...
                    'the\n%s value of the %sstep size tolerance%s, but the vector of ', ...
                    'function values\nis not near zero as measured by the %s value of the ',...
                    '%sfunction tolerance%s.\n\n%s\n'],noEqSolTag,endLinkTag,messageInfo{1}, ...
                    normStepTag,endLinkTag,messageInfo{3},stepSizeTolTag,endLinkTag,messageInfo{6}, ...
                    funcTolFsolveTag,endLinkTag,detailTag);
                
                detailedMsg = sprintf(['\n%s stopped because the %snorm of the current step%s, %e, ', ...
                    'is less than\n%soptions.TolX%s = %e. However, the sum of squared function values',...
                    ', r = %e,\nexceeds sqrt(%soptions.TolFun%s) = %e.\n\n', ...
                    'Optimization Metric                                      Options\n', ...
                    'norm(step) = %10.2e                            TolX = %7.0e (%s)\n', ...
                    'r = %10.2e                            sqrt(TolFun) = %8.1e (%s)\n'], ...
                    messageInfo{1},normStepTag,endLinkTag,messageInfo{2},tolXTag,endLinkTag, ...
                    messageInfo{4},messageInfo{5},tolFunFsolveTag,endLinkTag,messageInfo{7},messageInfo{2}, ...
                    messageInfo{4},messageInfo{3},messageInfo{5},messageInfo{7},messageInfo{6});
        end % switch caller - exitflag -22
    case infeasDeltaF % exitflag = -23
        switch caller
            case 'trustnleqn'
                % messageInfo = {'fsolve',relnorm(deltaF),tolFunChoice,tolFun,F'*F,tolFunChoice,sqrt(tolFun)}
                basicMsg = sprintf(['\n%sNo solution found%s.\n\n',...
                    '%s stopped because the %slast step was ineffective%s. However, the vector of function\nvalues ', ...
                    'is not near zero, as measured by the %s value of the %sfunction tolerance%s. \n\n%s\n'],noEqSolTag,...
                    endLinkTag,messageInfo{1},ineffectiveStepTag,endLinkTag,messageInfo{6},funcTolFsolveTag,endLinkTag,detailTag);
                
                detailedMsg = sprintf(['\n%s stopped because the sum of squared function values, r, changed ', ...
                    'by %e\nrelative to its initial value; this is less than max(%soptions.TolFun%s^2,eps) = %e.\n', ...
                    'However, r = %e, exceeds sqrt(options.TolFun) = %e.\n\n' ...
                    'Optimization Metric                                                 Options\n', ...
                    'relative change r = %10.2e                  max(TolFun^2,eps) = %7.0e (%s)\n', ...
                    'r = %10.2e                                      sqrt(TolFun) = %8.1e (%s)\n'],messageInfo{1}, ...
                    messageInfo{2},tolFunFsolveTag,endLinkTag,messageInfo{4},messageInfo{5},messageInfo{7},messageInfo{2}, ...
                    messageInfo{4},messageInfo{3},messageInfo{5},messageInfo{7},messageInfo{6});
            case {'snls','levenbergMarquardt'}
                % messageInfo = {'fsolve',relnorm(deltaF),tolFunChoice,tolFun,F'*F,tolFunChoice,sqrt(tolFun)}
                basicMsg = sprintf(['\n%sNo solution found%s.\n\n',...
                    '%s stopped because the %slast step was ineffective%s. However, the vector of function\nvalues ', ...
                    'is not near zero, as measured by the %s value of the %sfunction tolerance%s. \n\n%s\n'],noEqSolTag,...
                    endLinkTag,messageInfo{1},ineffectiveStepTag,endLinkTag,messageInfo{6},funcTolFsolveTag,endLinkTag,detailTag);
                
                detailedMsg = sprintf(['\n%s stopped because the sum of squared function values, r, changed ', ...
                    'by %e\nrelative to its initial value; this is less than %soptions.TolFun%s = %e.\n', ...
                    'However, r = %e, exceeds sqrt(options.TolFun) = %e.\n\n' ...
                    'Optimization Metric                                         Options\n', ...
                    'relative change r = %10.2e                     TolFun = %7.0e (%s)\n', ...
                    'r = %10.2e                              sqrt(TolFun) = %8.1e (%s)\n'],messageInfo{1}, ...
                    messageInfo{2},tolFunFsolveTag,endLinkTag,messageInfo{4},messageInfo{5},messageInfo{7},messageInfo{2}, ...
                    messageInfo{4},messageInfo{3},messageInfo{5},messageInfo{7},messageInfo{6});
        end % switch caller - exitflag -23
    case infeasSmallSearchDir % exitflag = -24
        switch caller
            case 'nlconst'
                % messageInfo = {'fmincon',normSD,tolXchoice,tolX,maxConstr,tolConChoice,tolCon}
                basicMsg = sprintf(['\n%sNo feasible solution found%s.\n\n',...
                    '%s stopped because the %ssize of the current search direction%s is less than\n',...
                    'twice the %s value of the %sstep size tolerance%s but constraints were not \nsatisfied to ',...
                    'within the %s value of the %sconstraint tolerance%s.\n\n%s\n'], ...
                    inFeasTag,endLinkTag,messageInfo{1},normSearchDirTag,endLinkTag,messageInfo{3}, ...
                    stepSizeTolTag,endLinkTag,messageInfo{6},constrTolTag,endLinkTag,detailTag);
                
                detailedMsg = sprintf(['\nOptimization stopped because the %snorm of the current search direction%s ', ...
                    ', %e,\nis less than 2*%soptions.TolX%s = %e, but the maximum constraint\n', ...
                    'violation, %e, exceeds %soptions.TolCon%s = %e.\n\n', ...
                    'Optimization Metric                                                Options\n', ...
                    'norm(search direction) = %10.2e                         TolX = %7.0e (%s)\n' ,...
                    'max(constraint violation)  = %10.2e                   TolCon = %7.0e (%s)\n'],normSearchDirTag,endLinkTag, ...
                    messageInfo{2},tolXTag,endLinkTag,messageInfo{4},messageInfo{5},tolConTag,endLinkTag,messageInfo{7}, ...
                    messageInfo{2},messageInfo{4},messageInfo{3},messageInfo{5},messageInfo{7},messageInfo{6});
            case 'levenbergMarquardt'
                %messageInfo = {'fsolve',norm(deltaX),tolXChoice,tolX,F'*F,tolFunChoice,sqrt(tolFun)}
                basicMsg = sprintf(['\n%sNo solution found%s.\n\n',...
                    '%s stopped because the relative %ssize of the current step%s is less than ',...
                    'the\n%s value of the %sstep size tolerance%s, but the vector of ', ...
                    'function values\nis not near zero as measured by the %s value of the ',...
                    '%sfunction tolerance%s.\n\n%s\n'],noEqSolTag,endLinkTag,messageInfo{1}, ...
                    normStepTag,endLinkTag,messageInfo{3},stepSizeTolTag,endLinkTag,messageInfo{6}, ...
                    funcTolFsolveTag,endLinkTag,detailTag);
                
                detailedMsg = sprintf(['\n%s stopped because the relative %snorm of the current step%s', ...
                    ', %e, is less than\n%soptions.TolX%s = %e. However, the sum of squared function values',...
                    ', r = %e,\nis less than sqrt(%soptions.TolFun%s) = %e.\n\n', ...
                    'Optimization Metric                                       Options\n', ...
                    'relative norm(step) = %10.2e                   TolX = %7.0e (%s)\n', ...
                    'r = %10.2e                            sqrt(TolFun) = %8.1e (%s)\n'], ...
                    messageInfo{1},normStepTag,endLinkTag,messageInfo{2},tolXTag,endLinkTag, ...
                    messageInfo{4},messageInfo{5},tolFunFsolveTag,endLinkTag,messageInfo{7},messageInfo{2},messageInfo{4}, ...
                    messageInfo{3},messageInfo{5},messageInfo{7},messageInfo{6});
        end % switch caller - exitflag -24
    case infeasDirDeriv % exitflag = -25
        % Create messages for display - caller is nlconst
        % messageInfo = {'fmincon',alpha*dirDeriv,tolXchoice,tolX,maxConstr,tolConChoice,tolCon}
        basicMsg = sprintf(['\n%sNo feasible solution found%s.\n\n',...
            '%s stopped because the %spredicted change in the objective function%s\n', ...
            'is less than the %s value of the %sfunction tolerance%s but constraints \nwere not satisfied to ',...
            'within the %s value of the %sconstraint tolerance%s.\n\n%s\n'], ...
            inFeasTag,endLinkTag,messageInfo{1},dirDerivTag,endLinkTag,messageInfo{3}, ...
            functionTolTag,endLinkTag,messageInfo{6},constrTolTag,endLinkTag,detailTag);
        
        detailedMsg = sprintf(['\nOptimization stopped because the %spredicted change in the objective function%s', ...
            ', %e,\nis less than %soptions.TolFun%s = %e, but the maximum constraint ', ...
            'violation,\n%e, exceeds %soptions.TolCon%s = %e.\n\n', ...
            'Optimization Metric                                                    Options\n',...
            'abs(steplength*directional derivative) = %10.2e           TolFun = %7.0e (%s)\n' ,...
            'max(constraint violation) = %10.2e                        TolCon = %7.0e (%s)\n'],dirDerivTag,endLinkTag, ...
            messageInfo{2},tolFunTag,endLinkTag,messageInfo{4},messageInfo{5},tolConTag,endLinkTag,messageInfo{7},...
            messageInfo{2},messageInfo{4},messageInfo{3},messageInfo{5},messageInfo{7},messageInfo{6});
    case infeasUndefGrads % exitflag = -26
        % Only caller is sqpLineSearch, do not break out by algorithm
        % messageInfo = {'fmincon',maxConstr,tolConChoice,tolCon}
        basicMsg = sprintf(['\n%sNo feasible solution found%s.\n\n',...
            '%s stopped because the %sgradient calculation is undefined%s. Constraints\n',...
            'were not satisfied to within the %s value of the %sconstraint tolerance%s.\n\n%s\n'], ...
            inFeasTag,endLinkTag,messageInfo{1},gradCalcFailTag,endLinkTag,messageInfo{3}, ...
            constrTolTag,endLinkTag,detailTag);
        
        detailedMsg = sprintf(['\nOptimization stopped because the objective or constraint ',...
            '%sgradient calculation is undefined%s\nat the current point and the relative maximum ', ...
            'constraint violation, %e,\nexceeds %soptions.TolCon%s = %e.\n\n', ...
            'Optimization Metric                                             Options\n', ...
            'relative max(constraint violation) = %10.2e        TolCon = %7.0e (%s)\n'], ...
            gradCalcFailTag,endLinkTag,messageInfo{2},tolConTag,endLinkTag,messageInfo{4}, ...
            messageInfo{2},messageInfo{4},messageInfo{3});
    case unbounded % exitflag = -3
        switch caller
            case {'barrier','sqpLineSearch'}
                % messageInfo = {'fmincon',fval,objLimitChoice,objLimit,maxConstr,tolConChoice,tolCon}
                basicMsg = sprintf(['\n%sProblem appears unbounded%s.\n\n',...
                    '%s stopped because the objective function value is less than\n', ...
                    'the %s value of the %sobjective function limit%s and constraints \nwere satisfied to ',...
                    'within the %s value of the %sconstraint tolerance%s.\n\n%s\n'], ...
                    unboundedTag,endLinkTag,messageInfo{1},messageInfo{3},objectiveLimitTag, ...
                    endLinkTag,messageInfo{6},constrTolTag,endLinkTag,detailTag);
                
                detailedMsg = sprintf(['\n%s stopped because the objective function value, %e, is less than\n', ...
                '%soptions.ObjectiveLimit%s = %e, and the relative maximum constraint\n', ...
                    'violation, %e, is less than %soptions.TolCon%s = %e.\n\n', ...
                    'Optimization Metric                                         Options\n', ...
                    'objective value = %10.2e               ObjectiveLimit = %7.0e (%s)\n', ...
                    'relative max(constraint violation) = %10.2e    TolCon = %7.0e (%s)\n'],messageInfo{1},messageInfo{2}, ...
                    objectiveLimitTag,endLinkTag,messageInfo{4},messageInfo{5},tolConTag,endLinkTag,messageInfo{7}, ...
                    messageInfo{2},messageInfo{4},messageInfo{3},messageInfo{5},messageInfo{7},messageInfo{6});
            case 'trustnleqn'
                % messageInfo = {'fsolve',trRadius,'',2*eps}
                basicMsg = sprintf(['\n%sNo solution found%s.\n\n',...
                    '%s stopped because the problem %sappears to be locally singular%s.\n\n%s\n'],noEqSolTrrTag,...
                    endLinkTag,messageInfo{1},localSingularTag,endLinkTag,detailTag);
                
                detailedMsg = sprintf(['\n%s stopped because the %strust-region radius%s, %e, is less than 2*eps.\n\n' ...
                    'Optimization Metric                                             Options\n', ...
                    'trust-region radius = %10.2e                              2*eps = %8.1e\n'],messageInfo{1}, ...
                    trRadiusTag,endLinkTag,messageInfo{2},messageInfo{2},messageInfo{4});
            case 'levenbergMarquardt'
                % messageInfo = {'fsolve',LMparam,'',0}
                basicMsg = sprintf(['\n%sNo solution found%s.\n\n',...
                    '%s stopped because the problem %sappears to be locally singular%s.\n\n%s\n'],noEqSolTrrTag,...
                    endLinkTag,messageInfo{1},localSingularLSQTag,endLinkTag,detailTag);
                
                detailedMsg = sprintf('\n%s stopped because the %sregularization parameter%s, %e, exceeds 1e16.\n', ...
                    messageInfo{1},regParamTag,endLinkTag,messageInfo{2});
        end
    otherwise
        basicMsg = sprintf('\nOptimization stopped.\nUnrecognized exitflag input to createExitMsg.\n');
end

if dispMsg                  % Display Message
    if ~detailedExitMsg
        disp(basicMsg)
    else
        disp(detailedMsg)
    end
end

% Create message for output structure.
if nargout > 0
    % Remove html tags from basicMsg
    basicMsg = regexprep(basicMsg,'</?(\w+).*?>','');
    % Remove "stopping criteria details" from basicMsg
    basicMsg = strtrim(regexprep(basicMsg,'<(\w+).*?>',''));
    detailedMsg = regexprep(detailedMsg,'</?(\w+).*?>',''); % Remove html tags from detailedMsg
    % Only separate messages by 'Stopping criteria details:' if there is a detailedMsg
    if ~isempty(detailedMsg)
        details = sprintf('\n\nStopping criteria details:\n');
    else
        details = '';
    end
    outputMsg = sprintf('%s%s%s',basicMsg,details,detailedMsg);   % Concatenate strings
    outputMsg = strtrim(outputMsg);  % Trim trailing newline chars and assign to output
end

Contact us