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
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(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)