batteryNominalEnergy=optimvar('batteryNominalEnergy',1,'LowerBound',0,'UpperBound',20); powerElectronicsRatedPower=optimvar('powerElectronicsRatedPower',1,'LowerBound',0,'UpperBound',10); Ppv_load=optimvar('Ppv_load',simTime,1,'LowerBound',0,'UpperBound',9.9824e+03); Ppv_batt=optimvar('Ppv_batt',simTime,1,'LowerBound',0); Ppv_grid=optimvar('Ppv_grid',simTime,1,'LowerBound',0,'UpperBound',9.9824e+03);Pcurtail=optimvar('Pcurtail',simTime,1,'LowerBound',0,'UpperBound',5000);Pbatt_load=optimvar('Pbatt_load',simTime,1,'LowerBound',0); Pbatt=Ppv_batt*Eta_inv-Pbatt_load/Eta_inv;Esoh=optimexpr(simTime,1);Esoh(1)=1;if Pbatt(i-1)>=0 %% this line reports the arror
Esoh(i)=Esoh(i-1)-0.2*(sampletime/gvarYEARS2SECONDS/20+0.5*Pbatt(i-1)*sampletime/(batteryNominalEnergy*gvarKWH2WS*Esoh(i-1))/4500);else Esoh(i)=Esoh(i-1)-0.2*(sampletime/gvarYEARS2SECONDS/20-0.5*Pbatt(i-1)*sampletime/(batteryNominalEnergy*gvarKWH2WS*Esoh(i-1))/4500);end
Hi, I have meet the problem in MATLAB using linprog. "Pbatt" can be positive or negative. when it is posive, the battery will be charging. And when it is negetive, the battery will be discharging. The equation above caculates the battery SOH whenever the battery is charging or discharging.
"Pbatt" is calculated from the optimization variables. But if I use "abs(Pbatt)", there will be an error that I can't use abs function.
Appreciate for your help!
Best Answer