# Convex minimization error

clear all; close all;

randn(‘seed’, 1);
T = 96; % 15 minute intervals in a 24 hour period
t = (1:T) ';
u = 2 * exp(-0.6 * cos((t+30) * pi/T) +0.05 * randn(T,1));
p = 0.1 * exp(-0.6 * cos((t+40) * pi/T) -0.7 * cos(t * 4 * pi/T)+0.01 * randn(T,1));

C = 2.5; D = 2.5;
%cvx_quiet(true);
cvx_begin
variables c(T,1) q(T,1);
minimize(p '* (u+c));
subject to
%q(1)==50
c >= -D; c <= C;
q >= 0; q <= 100;
sum( c )>=30;
sum( c )<=30.1;
q(2:T) == q(1:T-1) + c(1:T-1);
q(96,1)==100
u+c>0
cvx_end

hello everyone,

I have an minimization code and I would like to q(1)==50. If I remove starting point of q, code is working but initial point is around 70 and I cannot change it. Do you have any solution?

`q(1) == 50` makes the problem infeasible as reported by solver/CVX.

Changing the objective to
`minimize(q(1))`
results in optimal objective value of `67.4` for the few different random number instances I tried. Hence, that is the minimum value of `q(1)` for which your original problem is feasible. That value of `67.4` does depend on the collection of other constraints and input data values occurring in them.

The constraint `sum(c)<=30.1` is preventing `q(1) == 50` from being feasible, although I am not saying it is the only such constraint. I replaced `30.1` by a new variable `w`, made `w` the objective function, and included `q(1) == 50`. The following problem had optimal objective value `47.5`, which shows that at least for that random problem instance, if the constraint `sum( c )<=30.1` were changed to `sum( c )<= 47.5`, the problem would still be feasible even with `q(1) == 50`.

``````cvx_begin
variables c(T,1) q(T,1) w;
minimize(w);
subject to
q(1)==50
c >= -D; c <= C;
q >= 0; q <= 100;
sum( c )>=30;
sum( c )<=w;
q(2:T) == q(1:T-1) + c(1:T-1);
q(96,1)==100
u+c>0
cvx_end
``````

There are many other modifications to your model and input data which would make `q(1) == 50` feasible. Because it is your model, only you know what to do to improve the situation from your perspective.

Dr. Mark

In this case, I was trying to develop a EV charging case. q represents SoC and c represents battery capacity that is why I put limit between 30-30.1 which is the max. the capacity of the battery. I just trying to select the initial SoC of vehicles so I can optimize with different levels of demand. I am still trying to solve the problem but thank you for your help and for giving me another approach

Well, maybe the battery you chose can’t do what you want.