修改上述代码,使不同的t_list对应输出一个动态回收期P_t delta_s=[0.1:0.02:0.37]; %向共享储能电站售电的价格[0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37] t_list = zeros(size(delta_s)); % 对应的t值 for i=1:length(delta_s);%1:length(delta_s) delta_1 = delta_s(i); B1=(sum(delta_1.*P_ess_s(1,:))+sum(delta_1.*P_ess_s(2,:)))*365;%年卖弃光收益 B2(i)=B1; 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=72sum(P_max);%年运维成本 Cinv = @(t) (t==1)(1000sum(P_max)+1100sum(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));%净现值 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 t_list(i) = max_t; P_t =max_t-1+abs((sum(1+g).^(1:max_t-1)./(1+i0).^(1:max_t-1)).(B1(max_t-1)+C0(max_t-1)-Cinv(1)-C1(max_t-1)-C2(max_t-1)-Copr(max_t-1)))/(((1+g).^max_t./(1+i0).^max_t).(B1(max_t)+C0(max_t)-Cinv(1)-C1(max_t)-C2(max_t)-Copr(max_t)));%动态回收期 end disp(['delta_s = ', num2str(delta_s)]); disp(['净现值大于0的最初年份为: ', num2str(t_list),' 年']); disp(['动态回收期为: ', num2str(P_t),' 年']);
时间: 2024-04-28 14:22:06 浏览: 148
以下是修改后的代码:
delta_s=[0.1:0.02:0.37]; %向共享储能电站售电的价格[0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37]
t_list = zeros(size(delta_s)); % 对应的t值
for i=1:length(delta_s)
delta_1 = delta_s(i);
B1=(sum(delta_1.*P_ess_s(1,:))+sum(delta_1.*P_ess_s(2,:)))*365;%年卖弃光收益
B2(i)=B1;
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
t_list(i) = max_t;
P_t(i) = max_t-1+abs((sum((1+g).^(1:max_t-1)./(1+i0).^(1:max_t-1)).*(B1(max_t-1)+C0(max_t-1)-Cinv(1)-C1(max_t-1)-C2(max_t-1)-Copr(max_t-1)))/((1+g).^max_t./(1+i0).^max_t).*(B1(max_t)+C0(max_t)-Cinv(1)-C1(max_t)-C2(max_t)-Copr(max_t)));%动态回收期
end
disp(['delta_s = ', num2str(delta_s)]);
disp(['净现值大于0的最初年份为: ', num2str(t_list),' 年']);
disp(['动态回收期为: ', num2str(P_t),' 年']);
阅读全文