Home > matpower7.1 > mp-opt-model > lib > nlp_costfcn.m

nlp_costfcn

PURPOSE ^

NLP_COSTFCN Evaluates objective function, gradient and Hessian.

SYNOPSIS ^

function [f, df, d2f] = nlp_costfcn(om, x)

DESCRIPTION ^

NLP_COSTFCN  Evaluates objective function, gradient and Hessian.
   [F, DF, D2F] = NLP_COSTFCN(OM, X)

   Objective function evaluation routine, suitable for use with MIPS,
   FMINCON, etc. Computes objective function value, gradient and Hessian.

   Inputs:
     OM : Opt-Model object
     X : optimization vector

   Outputs:
     F   : value of objective function
     DF  : (optional) gradient of objective function (column vector)
     D2F : (optional) Hessian of objective function (sparse matrix)

   Examples:
       f = nlp_costfcn(om, x);
       [f, df] = nlp_costfcn(om, x);
       [f, df, d2f] = nlp_costfcn(om, x);

   See also NLP_CONSFCN, NLP_HESSFCN.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [f, df, d2f] = nlp_costfcn(om, x)
0002 %NLP_COSTFCN  Evaluates objective function, gradient and Hessian.
0003 %   [F, DF, D2F] = NLP_COSTFCN(OM, X)
0004 %
0005 %   Objective function evaluation routine, suitable for use with MIPS,
0006 %   FMINCON, etc. Computes objective function value, gradient and Hessian.
0007 %
0008 %   Inputs:
0009 %     OM : Opt-Model object
0010 %     X : optimization vector
0011 %
0012 %   Outputs:
0013 %     F   : value of objective function
0014 %     DF  : (optional) gradient of objective function (column vector)
0015 %     D2F : (optional) Hessian of objective function (sparse matrix)
0016 %
0017 %   Examples:
0018 %       f = nlp_costfcn(om, x);
0019 %       [f, df] = nlp_costfcn(om, x);
0020 %       [f, df, d2f] = nlp_costfcn(om, x);
0021 %
0022 %   See also NLP_CONSFCN, NLP_HESSFCN.
0023 
0024 %   MP-Opt-Model
0025 %   Copyright (c) 1996-2020, Power Systems Engineering Research Center (PSERC)
0026 %   by Ray Zimmerman, PSERC Cornell
0027 %
0028 %   This file is part of MP-Opt-Model.
0029 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0030 %   See https://github.com/MATPOWER/mp-opt-model for more info.
0031 
0032 %%----- evaluate objective function -----
0033 %% general nonlinear costs
0034 if nargout == 3
0035     [f, df, d2f]    = om.eval_nln_cost(x);
0036     if om.qdc.NS
0037         [fq, dfq, d2fq] = om.eval_quad_cost(x);
0038         f = f + sum(fq);
0039         df = df + dfq;
0040         d2f = d2f + d2fq;
0041     end
0042 elseif nargout == 2
0043     [f, df]   = om.eval_nln_cost(x);
0044     if om.qdc.NS
0045         [fq, dfq] = om.eval_quad_cost(x);
0046         f = f + sum(fq);
0047         df = df + dfq;
0048     end
0049 else
0050     f  = om.eval_nln_cost(x);
0051     if om.qdc.NS
0052         fq = om.eval_quad_cost(x);
0053         f = f + sum(fq);
0054     end
0055 end

Generated on Fri 09-Oct-2020 11:21:31 by m2html © 2005