修改这段代码,使不同delta_s的值输出一个对应的t,C0,C1 B1=(sum(delta_s.*P_ess_s(1,:))+sum(delta_s.*P_ess_s(1,:)))*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
时间: 2024-04-29 07:19:06 浏览: 150
Sigma_Delta.zip_Delta-Sigma matlab_Sigma_Delt_delta simulink_s
可以将代码修改如下:
delta_s = [0.1, 0.2, 0.3]; % 不同的delta_s值
t_list = zeros(size(delta_s)); % 对应的t值
for i = 1:length(delta_s)
delta = delta_s(i);
B1 = (sum(delta*P_ess_s(1,:))+sum(delta*P_ess_s(1,:)))*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));
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
max_t = t;
max_v = V_t;
end
end
end
t_list(i) = max_t;
end
disp(['delta_s = ', num2str(delta_s)]);
disp(['对应的t值为: ', num2str(t_list)]);
这样就能输出不同delta_s值对应的t了。
阅读全文