修改这段代码,将向共享储能电站售电的价格改为一个从0.2到0.37间隔为0.1的变量 gamma=[0.37*ones(1,32),1.36*ones(1,16),0.82*ones(1,20),1.36*ones(1,16),0.82*ones(1,12)]; %电网的"峰-平-谷"电价 delta=0.33*ones(1,96); %从共享储能电站购电的价格 delta_s=0.25*ones(1,96); %向共享储能电站售电的价格 P_load(1,:)=xlsread('fuhe.xlsx','sheet1','A1:CR1'); P_load(2,:)=xlsread('fuhe.xlsx','sheet1','A2:CR2'); P_pv(1,:)=xlsread('fuhe.xlsx','sheet1','A3:CR3'); P_pv(2,:)=xlsread('fuhe.xlsx','sheet1','A3:CR3'); P_ess_s(1,:)=xlsread('P-ess-s.xlsx','sheet1','A1:CR1'); P_ess_s(2,:)=xlsread('P-ess-s.xlsx','sheet1','A2:CR2'); P_ess_b(1,:)=xlsread('P-ess-b.xlsx','sheet1','A1:CR1'); P_ess_b(2,:)=xlsread('P-ess-b.xlsx','sheet1','A2:CR2'); P_grid(1,:)=xlsread('P-grid.xlsx','sheet1','A1:CR1'); P_grid(2,:)=xlsread('P-grid.xlsx','sheet1','A2:CR2'); g=0.03; i0=0.1; P_max=2161.4878 ; E_max=39700.8022 ; %%约束条件 %%目标函数 B1=(sum(delta_s.*P_ess_s(1,:))+sum(delta_s.*P_ess_s(2,:)))*365;%年卖弃光收益 C0=(sum(gamma.*P_load(1,:))+sum(gamma.*P_load(2,:)))*365; %年用户群不使用储能的情况下从电网购电费用(不是很懂) C1=(sum(gamma.*P_grid(1,:))+sum(gamma.*P_grid(2,:)))*365; %年用户群从电网购电费用 C2=(sum(delta.*P_ess_b(1,:))+sum(delta.*P_ess_b(2,:)))*365; %年用户群从储能电站购电 Copr=72*sum(P_max);%年运维成本 Cinv = @(t) (t==1)*(1000*sum(P_max)+1100*sum(E_max)); % 在t=1时为f(t),否则为0 max_t = -1; max_v = -Inf; for t = 1:20 V_t = sum((1+g).^(1:t)./(1+i0).^(1:t).*(B1+C0-Cinv(1:t)-C1-C2-Copr)); %求解净现值 if V_t >0 if max_t == -1 % 第一次发现 V_t 大于0 max_t = t; % 记录最初的年份 max_v = V_t; end end end if max_t == -1 % 净现值始终小于0 disp('净现值始终小于0'); else % 净现值大于0 disp(['净现值大于0的最初年份为: ', num2str(max_t),' 年']); end
时间: 2023-12-04 15:02:09 浏览: 104
修改后的代码如下:
```
gamma=0.2:0.1:0.37;
gamma=[gamma,1.36*ones(1,16),0.82*ones(1,20),1.36*ones(1,16),0.82*ones(1,12)]; %电网的"峰-平-谷"电价
delta=0.33*ones(1,96); %从共享储能电站购电的价格
delta_s=gamma; %向共享储能电站售电的价格
P_load(1,:)=xlsread('fuhe.xlsx','sheet1','A1:CR1');
P_load(2,:)=xlsread('fuhe.xlsx','sheet1','A2:CR2');
P_pv(1,:)=xlsread('fuhe.xlsx','sheet1','A3:CR3');
P_pv(2,:)=xlsread('fuhe.xlsx','sheet1','A3:CR3');
P_ess_s(1,:)=xlsread('P-ess-s.xlsx','sheet1','A1:CR1');
P_ess_s(2,:)=xlsread('P-ess-s.xlsx','sheet1','A2:CR2');
P_ess_b(1,:)=xlsread('P-ess-b.xlsx','sheet1','A1:CR1');
P_ess_b(2,:)=xlsread('P-ess-b.xlsx','sheet1','A2:CR2');
P_grid(1,:)=xlsread('P-grid.xlsx','sheet1','A1:CR1');
P_grid(2,:)=xlsread('P-grid.xlsx','sheet1','A2:CR2');
g=0.03;
i0=0.1;
P_max=2161.4878 ;
E_max=39700.8022 ;
%%约束条件
%%目标函数
B1=(sum(delta_s.*P_ess_s(1,:))+sum(delta_s.*P_ess_s(2,:)))*365;%年卖弃光收益
C0=(sum(gamma.*P_load(1,:))+sum(gamma.*P_load(2,:)))*365; %年用户群不使用储能的情况下从电网购电费用(不是很懂)
C1=(sum(gamma.*P_grid(1,:))+sum(gamma.*P_grid(2,:)))*365; %年用户群从电网购电费用
C2=(sum(delta.*P_ess_b(1,:))+sum(delta.*P_ess_b(2,:)))*365; %年用户群从储能电站购电
Copr=72*sum(P_max);%年运维成本
Cinv = @(t) (t==1)*(1000*sum(P_max)+1100*sum(E_max)); % 在t=1时为f(t),否则为0
max_t = -1;
max_v = -Inf;
for t = 1:20
V_t = sum((1+g).^(1:t)./(1+i0).^(1:t).*(B1+C0-Cinv(1:t)-C1-C2-Copr)); %求解净现值
if V_t >0
if max_t == -1 % 第一次发现 V_t 大于0
max_t = t; % 记录最初的年份
max_v = V_t;
end
end
end
if max_t == -1 % 净现值始终小于0
disp('净现值始终小于0');
else % 净现值大于0
disp(['净现值大于0的最初年份为: ', num2str(max_t),' 年']);
end
```
修改后的代码将 gamma 设置为从 0.2 到 0.37,间隔为 0.1 的变量,然后将向共享储能电站售电的价格 delta_s 设置为 gamma,即向共享储能电站售电的价格与电网的“峰-平-谷”电价相同。
阅读全文