your objective is not a scalar

709 views
Skip to first unread message

Salamino15

unread,
Aug 8, 2013, 12:11:23 AM8/8/13
to yal...@googlegroups.com
Hi,

I'm getting this error: Your objective is not a scalar (multiple solutions can currently only be obtained for linear objectives). Why is that??

Thanks in advance :)

obj = 0;
for k = 1:timeslots
    obj = obj + x(1,k)'*q*x(1,k); 
end

Johan Löfberg

unread,
Aug 8, 2013, 1:54:26 AM8/8/13
to yal...@googlegroups.com
You have defined a matrix. It does not make sense to minimize a matrix (I presume you agree)

Most likely, your code is something like this
obj = 0;
timeslots=2;
x
= sdpvar(1,timeslots);
q
= randn(timeslots);q = q*q';
for k = 1:timeslots
   obj = obj + x(1,k)'*q*x(1,k);
end

Look at obj!
>> obj
Quadratic matrix variable 2x2 (symmetric, real, 2 variables)

You probably want this
>> obj = x*q*x'
Quadratic scalar (real, homogeneous, 2 variables)


Salamino15

unread,
Aug 18, 2013, 11:07:54 PM8/18/13
to yal...@googlegroups.com
Oh! I know know what's wrong.. thanks Johan :)

I have an issue with the binary value in a program. All the matrix elements are 1, although only one element should be 1.

It's like the unit commitment example, each power plant should work at certain instances (one works all the time, the other less, .. )

Any idea what am I doing wrong??

Thank you :)

Johan Löfberg

unread,
Aug 19, 2013, 1:50:44 AM8/19/13
to yal...@googlegroups.com
Well, do you have any constraint that only one element is 1? sum(x)==1 would be the typical constraint for a binary vector x.

Salamino15

unread,
Aug 19, 2013, 6:06:46 PM8/19/13
to yal...@googlegroups.com
Got it now. Thank you :)

I have another objective function

obj = obj + ((p' * (others+p)*q*(others+p)') ./ (others+p)'); 

It's a sigmonial matrix variable 4x1 (full, real, 7 variables)!!

What should I do to make it scalar?? Sum it up maybe?

The decision variable is p while the other matrices have constant values...

Salamino15

unread,
Aug 19, 2013, 6:10:42 PM8/19/13
to yal...@googlegroups.com
An error occured when I sumed it up. What do you suggest as an easy way to express an objective function which has other matrices than that of the decision variable(s).. I'm getting confused! :(

Nonpositive terms in fractional expression in geometric program?

Johan Löfberg

unread,
Aug 20, 2013, 1:46:27 AM8/20/13
to yal...@googlegroups.com
What you do to create an objective cannot be answer, since it is a strange question.

Let us say you are modelling the design of a car, and you have a 4x1 vector objective (as you say you have)

x = [price fuelefficiency ugliness weight]

There is no way I can create an objective from that. It is up to you as the designer to decide upon what you want to optimize.

Johan Löfberg

unread,
Aug 20, 2013, 1:52:47 AM8/20/13
to yal...@googlegroups.com
The problem here is that YALMIP has tried to solve the problem using geometric programming (but discovered late in the compilation phase that it is not a geometric program)

How do you intend to solve the problem (did you expect it to be a GP?)

Which solver are you using?

Most likely, you have a nasty nonlinear program without any GP features. If that is the case, you are probably better of if you eliminate the fractions in the model, and write the relation using an equality instead

t = sdpvar(make it the same size as others+p)
obj
= obj + t;
Constraints = [Constraints, t
.*(others+p)' == ((p' * (others+p)*q*(others+p)')];

As I said though, this sounds like a really nasty nonlinear program, so don't expect to much from the solutions

Salamino15

unread,
Aug 20, 2013, 2:21:30 AM8/20/13
to yal...@googlegroups.com
Hi Johan,

The function I'm working on is shown below. I should minimize Bn. This should be a mixed integer linear program with two decision variables 
->>> on = binvar(1, timeslots) and 
xn = sdpvar(1, timeslots) - it's somehow similar to the unit commitment problem where on indicates when a power plant is on and xn indicates its power. 

The decision variable xn is clearly found in the numerator and is also part of the summation of xm (sum of xm = x1 + x2 + xn + ... + xN) - so it's in the numerator and also in the denominator. 

How should I model this correctly?? Thanks in advance :)




Johan Löfberg

unread,
Aug 20, 2013, 2:33:42 AM8/20/13
to yal...@googlegroups.com
As I said, I would remove fraction by introducing new variables and equalities. Most solvers behave better when fractions are removed, as they can cause singularities in infeasible points.

If you have the objective x1/(x1+x2) + x2/(x3+x4), you define¨two new variables t1 and t2 and use the objective t1+t2, and add the constraints t1*(x1+x2) == x1 and t2*(x3+x4)==x2

in you case, you would define new variables z(n,h) and add the constraints  z(n,h) *sum_m(x) == x(n,h), and define Bn as sum_h z(n,h)Ch sum_m x(m,h).

Johan Löfberg

unread,
Aug 20, 2013, 2:35:41 AM8/20/13
to yal...@googlegroups.com
BTW, if x is binary, you can most likely derive a much better model where you get rid of all nonlinearities etc. Many people make mistakes when they model unit-commitment and similar by multiplying variables with binary variables etc, when they really should use linear constraints to model that things are turned on/off

Salamino15

unread,
Aug 21, 2013, 8:07:00 PM8/21/13
to yal...@googlegroups.com
Let me rephrase then. I want to place this matrix representing power p = [20 15 10] (as in figure) in any hour of the day such that the total costs of the day are minimum where hourly costs matrix c = [3 3 4 4 5 5 ... ]. 

It's just confusing me because the example I am building my work upon (unit commitment) doesn't tackle power matrices with different values, it only defines the upper limit of the power to be used. Is it clearer now?? Should I make a matrix with the objectives resulting from placing at each hour of the day and then choose the minimum value?? or do that for the constraints?? I'm getting confused :(


Salamino15

unread,
Aug 21, 2013, 8:08:26 PM8/21/13
to yal...@googlegroups.com
Maybe it wasn't clear but the first value of p would be at hour h1, second value of p would be at hour h2, .. etc
I need to choose the hour at which this power matrix should be allocated to get the minimum cost..

Johan Löfberg

unread,
Aug 22, 2013, 1:34:46 AM8/22/13
to yal...@googlegroups.com
So you mean
x = [20 15 10 0 0 0 0 ..

or

x = [0 20 15 10 0 0 0.. ]

or 

x = [ 0 0 20 15 10 ..]

The only approach I see is the trivial enumeration, i.e.

Cases = [20 15 10 0 0 0 ..;0 20 15 10 0 0 ...;0 0 20 15 10 . . . ]

d = binvar(size(Cases,1),1);
x = d'*Cases
Model = [sum(d)==1]




Salamino15

unread,
Aug 22, 2013, 3:52:11 PM8/22/13
to yal...@googlegroups.com
It worked out well...
Thank you so much Johan :)
Reply all
Reply to author
Forward
0 new messages