# Vector optimization in CVX Matlab

(Lau) #1

Hey guys

I have the following problem to solve,

``````clear all
clc
format long g

cvx_startup

n = 2; % I want to run this problem for n=8760 (which number of hours in a year), but im just trying to do it for 1 hour in the beginning.

CO2   = Data(1:n,2);
q        = Data(1:n,1);

P     = (price(:,8)+price(:,10))/2;

a = 15; % close to inelastic demand
b = zeros(n,1);

for i = 1:n

b(i) = a*q(i)+P(i);

end

cvx_begin
variables S(n) CS(n) PS(n) q(n) R(n) Lambda(n) P2(n) q2(n) c d
maximize (S)
subject to
S == CS + PS
CS == ((b-P2).*q2)/2
PS ==  q2.*(P-0.17*q2+23)+((P-23).*q2)/2
R == Lambda .* q2
q2 == (b-P2)/a
P2 == Lambda + P
sum(R) >= (10000000000 / (365 * 24)) * n
Lambda == c*CO2.^2+d
cvx_end
``````

The error that I get is:

Error using .* (line 262)
Disciplined convex programming error:
Invalid quadratic form(s): not a square.

Error in Untitled4 (line 29)
CS == ((b-P2).q2)/2
%int(-a
q2+b,[0 q2])

Thanks for the help in advance

(Mark L. Stone) #2

There a re a lot of problems with your code. Here are some, but not necessarily all, of them.

The objective function must evlauate to real scalar. Yours is not when n >= 2. you need to formulate a scalar objective,

You are multiplying CVX (optimiation, a.k.a. decision) variables like it’s going out of style. That is not allowed in CVX Please read Why isn't CVX accepting my model? READ THIS FIRST! and http://cvxr.com/cvx/doc/ .

I can’t tell you how to fix your program because I have no idea what you are trying to do. I have no idea when all is said and done whether you will have a convex optimization problem.

(Lau) #3

Thanks for the quick response!

I am trying to determine a dynamic tax (Lambda), which gets progressively bigger as the average CO2 per kWh produced increases (CO2). I am trying to do this through a social welfare optimization (S), where the social welfare equals the combination of Consumer Surplus (CS) and Producer Surplus (PS). The equation for CS and PS is the area under a graph. The revenue ® is collected in each hour (n), and is the tax rate multiplied with the consumption. We want the tax rate (Lambda) to follow a quadratic equation and have it to be related with CO2. Finally there is also a constraint that says the sum of revenue in all hours have to generate a certain amount (the inequality constraint).

I can change the objective function to the sum of S. Would that solve that problem?

I am not sure how to check for convexity in this? Normally I would take the hessian of the objective and the calculate the eigenvalue.

(Mark L. Stone) #4

This is not a modeling forum. so you’ll have to figure out what your model should be. It is up to you (as far as this forum is concerned) what your objective function is. If that is sum(S), where S is a vector variable then it is affine, and so can be maximized (or minimized). However, in order to use CVX, your constraints must be convex.

Please study the links my previous post.in this thread. You may also wish to study and do solve some of the exercises in http://web.stanford.edu/~boyd/cvxbook/ .