As shown in the figure, i think the output result of function square_pos in cvx is wrong,can you help me?
Yes, that is wrong. Perhaps there is a conflict somewhere. It might be the case that square_pos
when applied to a cvx variable or expression is correct, because that uses an “internal” version of square_pos
.
Is there another square_pos
in your MATLABPATH besides these two? If so, perhaps the “wrong” square_oos
is being called.
>> which -all square_pos
C:\cvx_2.2_1148\functions\square_pos.m
C:\cvx_2.2_1148\functions\@cvx\square_pos.m % cvx method
Below is the version of square_pos
for double precision arguments: it is located in the functions
directory of the CVX installation.
function y = square_pos( x )
%SQUARE_POS Square of positive part.
% SQUARE_POS(X) is the square of the postive parts of the elements of X;
% i.e., SQUARE_POS(X)=MAX(X,0).^2. X must be real.
%
% Disciplined convex programming information:
% SQUARE_POS(X) is convex and nondecreasing in X. Thus when used in
% CVX expressions, X must be convex (or affine).
narginchk(1,1);
if ~isreal( x ),
error( 'Argument must be real.' );
end
y = square( max( x, 0 ) );
% Copyright 2005-2016 CVX Research, Inc.
% See the file LICENSE.txt for full copyright information.
% The command 'cvx_where' will show where this file is loc