⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eval.m

📁 HERE IS A GOOD PSO TOOL BOX
💻 M
字号:
function r = eval(obj, vars)% GPOSYNOMIAL/EVAL  Implements EVAL command for general posynomials.%% Returns reduced generalized 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% evaluate immediately if gposy has a single termif( strcmp(obj.op,'obj') )  r = eval(obj.args{:},vars);  returnend% now evaluate classic gposynomials% make sure all arguments can be evaluated (convert constants to constant monos)for k = 1:length(obj.args)  if( isnumeric(obj.args{k}) )    obj.args{k} = monomial(obj.args{k});  endend % evaluate different flavors of gposynomial% power gposynomialif( isnumeric(obj.op) )  r = (eval(obj.args{1},vars))^(obj.op);% times gposynomialelseif( strcmp(obj.op,'*') )  r = (eval(obj.args{1},vars))*(eval(obj.args{2},vars));% plus gposynomialelseif( strcmp(obj.op,'+') )  r = (eval(obj.args{1},vars))+(eval(obj.args{2},vars));% max gposynomialelseif( strcmp(obj.op,'max') )  num_args = [];  obj_args = {};  for k = 1:length(obj.args)    value = eval(obj.args{k},vars);    if( isnumeric(value) )      num_args(end+1) = value;    else      obj_args = { obj_args{:} value };    end  end  num_max = max(num_args);  if( ~isempty(obj_args) )    if( ~isempty(num_max) )      obj_args = {obj_args{:} num_max};    end    r = max(obj_args{:});  else    r = num_max;  endend

⌨️ 快捷键说明

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