How to vectorize SOC constraints

57 views
Skip to first unread message

Tomasz Gorecki

unread,
May 20, 2015, 7:06:36 AM5/20/15
to yal...@googlegroups.com
Hello, in an attempt to speed up the Yalmip parsing I was trying to vectorize as much as possible my constraints declarations.

I have a bunch of SOC constraints of the form

for i = 1:n
norm
(Z(i,:),2) <= z(i)
end

I tried also the manual version

Z(i,:)*Z(i,:)' <= z(i)

which was quite slower but was wondering if there is a way of getting away without for loops, or what is the best practice for this

Best and thanks in advance,

Tomasz

Johan Löfberg

unread,
May 20, 2015, 7:12:39 AM5/20/15
to yal...@googlegroups.com

cone([z(:)';Z'])


Tomasz Gorecki

unread,
May 20, 2015, 7:33:53 AM5/20/15
to yal...@googlegroups.com
Great thx.
Does something similar exist for other cones (inf, 1-norm, sdp ?)

Tomasz Gorecki

unread,
May 20, 2015, 7:57:25 AM5/20/15
to yal...@googlegroups.com
I spoke too fast,

I tried:
cone(z(:)',Z')

but got the error
Error using subsindex
Function 'subsindex' is not defined for values of class 'sdpvar'.

the input arguments have dimension 1x404 and 30x404 respectively

Johan Löfberg

unread,
May 20, 2015, 7:58:55 AM5/20/15
to yal...@googlegroups.com
You missed the brackets.

And no, this is only for 2-norm, as inf and 1-norm are trivially modelled manually if max performance is needed.

Johan Löfberg

unread,
May 20, 2015, 7:59:50 AM5/20/15
to yal...@googlegroups.com
and with dimensions the data is simply [z;Z]

Johan Löfberg

unread,
May 20, 2015, 8:03:02 AM5/20/15
to yal...@googlegroups.com
and the error message is because you have a constant variable called cone

Tomasz Gorecki

unread,
May 20, 2015, 8:13:37 AM5/20/15
to yal...@googlegroups.com
I tried different arragement of data but cannot get past this error. Even trying just

z = sdpvar(10,10,'full')
Linear matrix variable 10x10 (full, real, 100 variables)
cone(z)

still gives

Error using subsindex
Function 'subsindex' is not defined for values of class 'sdpvar'.

Sorry if I am doing something idiotic

Best

Tomasz Gorecki

unread,
May 20, 2015, 8:14:44 AM5/20/15
to yal...@googlegroups.com
ah yes sure that was it. I had a cone variable.
Reply all
Reply to author
Forward
0 new messages