eval.m

来自「HERE IS A GOOD PSO TOOL BOX」· M 代码 · 共 32 行

M
32
字号
function r = eval(obj, vars)% POSYNOMIAL/EVAL  Implements EVAL command for posynomials.%% Returns reduced posynomial where all the GP variables with given% numerical values are evaluated.%sz = size(vars);if( ~isa(vars,'cell') || sz(2) ~= 2 )  error('Second argument should be a cell array with 2 rows');end% check that all the gp variables are positive (implicit GP constraint)for k = 1:size(vars,1)  var_values = vars{k,2};  if any(var_values <= 0)    error('GP variables must have positive value.');  endend% posynomial evaluationr = posynomial;for k = 1:obj.mono_terms  r = r + eval(obj.monomials{k},vars);endif isempty(r.gpvars) % have a numeric result  r = r.monomials{1};  r = r.c;  if isempty(r), r = 0; endend

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?