isequal.m
来自「HERE IS A GOOD PSO TOOL BOX」· M 代码 · 共 33 行
M
33 行
function r = isequal(m1, m2)% MONOMIAL/ISEQUAL Checks if two monomials are equal.% Example: x*y and y*x are equal.%% make sure both are monomialsm1 = monomial(m1);m2 = monomial(m2);% assume true state (monomials are equal)r = 1; % first check if they have same number of gpvarsif( length(m1.gpvars) ~= length(m2.gpvars) ) r = 0; % monomials cannot be equal return;end% check that both have the same variablesif ~isempty(setdiff(m1.gpvars, m2.gpvars)) r = 0; % monomials cannot be equal return;end% now check that both have the same exponentsfor k = 1:length(m1.gpvars) [tf, loc] = ismember( m1.gpvars{k}, m2.gpvars ); % check the variable exponents if( m1.a(k) ~= m2.a(loc) ) r = 0; % monomial are not equal return; endend
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?