Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.



Re: pls Help with fmincon!
Posted:
Aug 23, 2013 6:54 AM


> 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_demandP_prod; > > % xstart > P_market_start=P_demandP_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]; > > %% > % * 'interiorpoint' > % * 'sqp' > % * 'activeset' > % * 'trustregionreflective' (default) > > options = optimset('Algorithm','interiorpoint'); > [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^24*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_battSoc_batt_start)^2; > > end > ////////////////////////////////////////////////////// > //////////// > > Any advice to change or add something to the script? > >
Your matrix Aeq has 432 columns and your xvector has 3 elements, but the number of columns of Aeq and the dimension of the xvector must coincide ...
Best wishes Torsten.



