Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: pls Help with fmincon!
Replies: 6   Last Post: Aug 23, 2013 6:54 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Torsten Hennig

Posts: 2,419
Registered: 12/6/04
Re: pls Help with fmincon!
Posted: Aug 23, 2013 6:54 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

> I am trying to optimize the energy usage in a smart
> house using fmincon to make it profitable for the
> user. The house has a solar panel and a wind turbine
> that generate energy, a consumption profile that show
> much much energy the house need. The energy storage
> is used as a battery in the basement and a plugged in
> Electric Vehicle (EV) during a certain time during
> the day. The optimization will be for the next 24
> hours that i have estimated, based on that i will
> make a decision what to do the next time step. I have
> access to data every 10 min, which means 24h*6=144
> data. The system can use both the EV and the battery
> to save or to drain energy from the battery and EV.
> According a study i made i will keep the state of
> charge of the battery and EV between 15%-85% and
> there is a maximum of charging/discharging energy
> from the battery. In the problem i have included the
> energy prices for both
> sell and buy, since the price to buy energy is higher
> than selling. I have excluded the EV to make it
> simple in the beginning and will include it later.
> The problem is that i get the output of the variables
> out of bound. The code is presented below!
>
> ///////////////////////////////main///////////////////
> //////////////////
>
> P_demand=10*ones(144,1); % house consumption
> P_prod=1*ones(144,1); % house energy production
>
>
> % equalities
> Aeq=zeros(144,432);
> Aeq(1,1:3)=[1 1 0];
> for i=1:143
> Aeq(i+1,(3*i+1):(i+1)*3)=[1 1 0];
> end
> Beq=P_demand-P_prod;
>
> % xstart
> P_market_start=P_demand-P_prod; % count how much to
> sell and buy energy
> P_batt_start=zeros(144,1); % battery effect charge or
> discharge the battery
> Soc_batt_start=0.5*ones(144,1); % start battery level
>
> x0=[P_market_start P_batt_start Soc_batt_start];
>
> % Lb
> P_market_Lb=-inf; %x1
> P_batt_Lb=-3400; %x2
> Soc_batt_Lb=0.15; %x3
> Lb=[P_market_Lb; P_batt_Lb; Soc_batt_Lb];
>
> % Ub
> P_market_Ub=inf; %x1
> P_batt_Ub=1020; %x2
> Soc_batt_Ub=0.85; %x3
> Ub=[P_market_Ub; P_batt_Ub; Soc_batt_Ub];
>
> %%
> % * 'interior-point'
> % * 'sqp'
> % * 'active-set'
> % * 'trust-region-reflective' (default)
>
> options = optimset('Algorithm','interior-point');
> [x,fval]=
> fmincon(@optObjective1,x0,[],[],Aeq,Beq,Lb,Ub,[],optio
> ns)
>
> /////////////////////////optObjective1////////////////
> /////////////////////////////
>
> function f = optObjective1(x)
>
> P_market=x(1);
> P_batt=x(2);
> Soc_batt=x(3);
> Soc_batt_start=0.5;
>
>
> Price_buy=1;
> Price_sell=1;
>
> Uoc=5000;
> Ri=100;
> Q0=24000/Uoc;
> dt=600;
> c=1;
> f1=zeros(1,1);
> f2=zeros(1,1);
>
>
> Ib=(Uoc - sqrt(Uoc^2-4*Ri*P_batt))/2*Ri;
>
> Soc_batt=(-Ib/Q0)*dt + Soc_batt;
>
>
> if P_market<=0
> f1=P_market;
> f2=0;
> else
> f1=0;
> f2=P_market;
> end
>
>
> f=f1.*Price_buy + f2.*Price_sell
> +c*(Soc_batt-Soc_batt_start)^2;
>
> end
> //////////////////////////////////////////////////////
> ////////////
>
> Any advice to change or add something to the script?
>
>


Your matrix Aeq has 432 columns and your x-vector has 3 elements, but the number of columns of Aeq and the dimension of the x-vector must coincide ...

Best wishes
Torsten.



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.