function y = times(X,Y) %TIMES (overloaded) % Check dimensions [n,m]=size(X); if ~((prod(size(X))==1) || (prod(size(Y))==1)) if ~((n==size(Y,1) && (m ==size(Y,2)))) error('Matrix dimensions must agree.') end end; % Convert block objects if isa(X,'blkvar') X = sdpvar(X); end if isa(Y,'blkvar') Y = sdpvar(Y); end if isnumeric(X) if any(isnan(X)) error('Multiplying NaN with an SDPVAR makes no sense.'); end end if isnumeric(Y) if any(isnan(Y)) error('Multiplying NaN with an SDPVAR makes no sense.'); end end if isempty(X) YY = full(reshape(Y.basis(:,1),Y.dim(1),Y.dim(2))); y = X.*YY; return elseif isempty(Y) XX = full(reshape(X.basis(:,1),X.dim(1),X.dim(2))); y = XX.*Y; return end if (isa(X,'sdpvar') && isa(Y,'sdpvar')) X = flush(X); Y = flush(Y); if (X.typeflag==5) && (Y.typeflag==5) error('Product of norms not allowed'); end if numel(X)==1 && numel(Y) > 1 X = repmat(X,size(Y)); elseif numel(Y)==1 && numel(X) > 1 Y = repmat(Y,size(X)); end try y = check_for_special_case(Y,X); if ~isempty(y) return end % Check for the case x.*y where x and y are unit variables [mt,variable_type,hashedMT,hash] = yalmip('monomtable'); if length(X.lmi_variables)==numel(X) if length(Y.lmi_variables) == numel(Y) if numel(X)==numel(Y) % This looks promising. write as (x0+X)*(y0+Y) X0 = reshape(X.basis(:,1),X.dim); Y0 = reshape(Y.basis(:,1),Y.dim); Xsave = X; Ysave = Y; X.basis(:,1)=0; Y.basis(:,1)=0; if nnz(X.basis)==numel(X) if nnz(Y.basis)==numel(Y) D = [spalloc(numel(Y),1,0) speye(numel(Y))]; if isequal(X.basis,D) if isequal(Y.basis,D) % Pew. Z = X; generated_monoms = mt(X.lmi_variables,:) + mt(Y.lmi_variables,:); generated_hash = generated_monoms*hash; keep = zeros(1,numel(X)); if all(generated_hash) && all(diff(sort([generated_hash;hashedMT]))) Z.lmi_variables = size(mt,1)+(1:numel(X)); keep = keep + 1; else for i = 1:numel(X) if generated_hash(i) before = find(abs(hashedMT-generated_hash(i))0; y_base_not_zero = nnz(Ybase)>0; for i = 1:length(all_lmi_variables) base = 0; if index_Y(i) && x_base_not_zero base = Xbase.*getbasematrixwithoutcheck(Y,index_Y(i)); end if index_X(i) && y_base_not_zero base = base + getbasematrixwithoutcheck(X,index_X(i)).*Ybase; end Z.basis(:,i+1) = base(:); end % Nonlinear terms i = i+1; ix=1; new_mt = []; %mt = yalmip('monomtable'); nvar = length(all_lmi_variables); local_mt = mt(all_lmi_variables,:); theyvars = find(index_Y); thexvars = find(index_X); hash = randn(size(mt,2),1); mt_hash = mt*hash; for ix = thexvars(:)' % if mx==1 Xibase = X.basis(:,1+index_X(ix)); % else % Xibase = reshape(X.basis(:,1+index_X(ix)),nx,mx); % end mt_x = local_mt(ix,:); y_basis = Y.basis(:,1+index_Y(theyvars)); x_basis = repmat(Xibase,1,length(theyvars(:)')); if y_isscalar && ~x_isscalar y_basis = repmat(y_basis,nx*mx,1); elseif x_isscalar && ~y_isscalar x_basis = repmat(x_basis,ny*my,1); end allBase = x_basis.*y_basis; jjj = 1; usedatall = find(any(allBase,1)); % for iy = theyvars(:)' for iy = theyvars(usedatall(:))' % ff=Y.basis(:,1+index_Y(iy)); % Yibase = reshape(ff,ny,my); % prodbase = Xibase.*Yibase; prodbase = allBase(:,usedatall(jjj));jjj = jjj+1; % prodbase = reshape(prodbase,ny,my); if (norm(prodbase,inf)>1e-12) mt_y = local_mt(iy,:); % Idiot-hash the lists new_hash = (mt_x+mt_y)*hash; if abs(new_hash)1) || (min(size(Y))>1) return end if ~all(size(Y)==size(X)) return end entropies = zeros(length(Y),1); if is(X,'linear') argst = yalmip('getarguments',Y); if length(argst)~=length(X) return end if length(argst) == 1 args{1} = argst; else args = argst; end for i = 1:length(args) if isempty(args{i}) return end if isequal(args{i}.fcn,'log') S(1).subs={i}; S(1).type='()'; Z = subsref(X,S); if isequal(Z.basis,args{i}.arg{1}.basis) if isequal(Z.lmi_variables,args{i}.arg{1}.lmi_variables) entropies(i) = 1; end end end end end if all(entropies) y = -ventropy(X); end