Above code is a part of optimization i am working on(Optimal control of hybrid energy storage system). While running the code, the values of variables(Pb, Psca,Esc,Psc) are zero til t=(tn-2) and incorrect values for Pb(tn-1) & Pb(tn).
This is the exact code layout am working. Besides the decision variables, all other variables are given or calculated before the ‘cvx begin’.
What I am trying to implement is,
Every variable is a function of t as t varies from t=1 to tn.
Even the non decision variables are also function of t(1:tn).
For final result i will have the plot for t vs Pb(t) and other variables.
As of now, the CVX runs, either it shows inaccurate/solved or sometimes solved but not the expected values.
This is based on the Penalty Function approximation given in CVX examples. I have checked most of the examples regarding the same and still checking if anyone has done similar in the forum. If you have come across similar optimization problem then please link the same.
Note: The problem was solved using CVX by the author of the paper. But i am sure my model layout is wrong.
The code is running for “tn” elements by adding one "‘for’ loop inside the CVX portion. Even though not the expected results, but its close to the expected one. Will have to carefully look at the mathematical model for any errors.
Is your objective function supposed to only be in terms of the 1000th and 999th elements of various vectors? I don’t know, but that’s what you have done. You are allowed to use sum or a for loop to build up an objective function expression prior to the minimize statement.
You can use a for loop for the constraint, and perhaps you need to do so forEsc(tn)-Esc(tn-delta)== -Psc(tn)*delta;. But for instance,Pb+Psca+Preq== 0; without use of a for loop will impose this equality on all 1000 elements, i.e., specifies 1000 inequalities. Similarly, Esc_min<=Esc<=Esc_max; .
You need to figure out what you are doing with Pb. As I wrote, you’re setting of Pb before cvx_begin is overridden once you declare it a CVX variable after cvx_begin.