using the max function in the objective function

69 views
Skip to first unread message

Yujia Wang

unread,
Jan 23, 2013, 4:57:05 PM1/23/13
to yal...@googlegroups.com
Hi all,

I am trying to solve a minimax problem in yalmip and am getting quite confused about how yalmip is handling the setup.  If I uncomment the line that sets up f_y also as a sdpvar, the program yields a X that looks reasonable.  But with the line commented out, yalmip keeps resulting in something like a constant times the identity matrix.  Am a setting this up wrong?

X = sdpvar(N);
% f_y = sdpvar(M,1);

for i = 1:M
     f_y(i) = trace( J{i} * X );
end 
obj = max(abs(f_y));

sol = solvesdp( [X>= 0], obj);

Johan Löfberg

unread,
Jan 24, 2013, 9:27:08 AM1/24/13
to
Hi,

I belive you've stumbled an annoying features of the OO framework in MATLAB. If an object is assigned to an existing double, the object is first cast as a double, and there is no way to change that behavior

% This will generate y=[1 nan]
sdpvar x
y = [1 1]
y(2)=x

% This will generate y=[1 3]
sdpvar x
y = [1 1]
assign(x,3)
y(2)=x

As per MATLABs OO specs, the two expressions above are equivalent to

y(2)=double(x);

If y doesn't exist, it works as expected.

% This will generate y = x
sdpvar x
clear y
y(1)=x

From this, I guess that you have f_y defined as a double before entering this part of you code, thus causing your issues. Either, you predefine f_y as an sdpvar as you've done, but a more MATLAB-stylish approach would be

f_y = [];
for i = 1:M
    f_y(i) = [f_y;trace( J{i} * X )];
end

Finally, don't use max(abs(f_y)). This will cause YALMIP to first model the abs value operators, and then the max operator, leading to a lot of analysis for convexity checks etc. Much easier to simply use norm(f_y,1)

Yujia Wang

unread,
Jan 24, 2013, 3:57:25 PM1/24/13
to yal...@googlegroups.com
Hi Johan,

This seems to have solved the problem, thanks very much for  the help.
Reply all
Reply to author
Forward
0 new messages