% 清除命令窗口和工作空间
clear
clc
% 设置输入参数
nigue = 0.339;
nique = 0.958;
guangfus = 2964.096;
beilv = 100000;
loss_factor = 0.1257971066767019;
% 负载功率数据
P_load = [8.54433, 8.39421, 8.03142, 7.78122, 7.61859, 7.18074, 6.74289, 7.24329, 7.76871, 8.0064, 8.29413, 8.21907, 8.33166, 8.33166, 7.98138, 7.68114, 7.3809, 7.99389, 8.84457, 8.70696, 8.54433, 8.30664, 8.20656, 8.39421, 5.57946, 5.57946, 5.2542, 4.94145, 5.24169, 5.66703, 7.03062, 7.21827, 7.1307, 7.09317, 7.16823, 7.0056, 7.0056, 6.66783, 6.93054, 6.68034, 6.71787, 6.61779, 6.68034, 6.40512, 7.11819, 6.74289, 6.45516, 5.80464, 6.40512, 6.48018, 5.99229, 6.02982, 6.20496, 6.94305, 7.89381, 7.71867, 7.96887, 7.55604, 7.506, 7.46847, 7.26831, 6.99309, 7.28082, 6.8805, 6.81795, 7.08066, 7.93134, 8.14401, 7.6311, 6.94305, 6.65532, 5.99229, 8.43174, 8.09397, 8.06895, 8.14401, 8.29413, 8.61939, 8.81955, 8.84457, 9.31995, 8.94465, 9.15732, 9.04473, 9.26991, 9.19485, 9.04473, 9.52011, 9.44505, 9.60768, 9.43254, 9.83286, 9.30744, 8.78202, 8.64441, 8.71947];
% 总辐射和电价数据
data1 = [0,0,0,0,0,0,0,2.608666667,76.80142857,248.7866667,457.8183333,666.9881356,712.2,884.4491525,864.5578947,712.7517241,416.6644068,124.0768966,69.65,11.37518644,0,0,0,0,0,0,0,0,0,0,0,33.95430357,265.3160714,452.84,522.7245614,500.8517241,526.9516667,615.037931,550.4603448,179.279661,95.55089286,430.1233333,348.1389831,125.0282143,0,0,0,0,0,0,0,0,0,0,0,12.48563158,137.9455932,130.159322,290.6983051,261.8118644,540.5603448,375.1,438.3169492,625.5915254,625.1140351,356.237931,171.7003448,9.634833333,0,0,0,0,0,0,0,0,0,0,0,1.796016949,22.56477586,167.3735593,392.695,564.0896552,685.0305085,577.7118644,653.3169492,628.3101695,380.059322,147.5068966,51.02083333,3.152101695,0,0,0,0];
data2 = [8.42, 7.91, 7.36, 7.245, 7.985, 11.575, 12.875, 11.865, 12.495, 13.87, 15.435, 15.58, 17.625, 17.74, 15.615, 12.355, 13.325, 12.405, 12.535, 11.715, 11.005, 9.59, 9.37, 9.155, 12.235, 11.52, 8.5, 8.505, 8.475, 8.78, 12.955, 18.605, 15.91, 15.005, 14.855, 15, 14.96, 14.725, 12.505, 12.105, 13.97, 36.43, 32.81, 20.56, 18.07, 14.63, 15.59, 15, 8.33, 8.32, 7.84, 6.235, 6.61, 8.29, 9.74, 11.01, 11.47, 13.25, 14.51, 14.59, 13.99, 14.225, 14.725, 14.095, 13.605, 12.625, 12.915, 10.985, 10.75, 9.865, 10.29, 11.66, 10.175, 8.625, 8.275, 8.245, 8.75, 11.26, 11.295, 11.225, 13.635, 14.58, 14.365, 12.95, 13.005, 12.805, 11.7, 12.03, 11.2, 10.985, 9.22, 9.165, 8.545, 7.665, 8.76, 10.91];
data = {data1; data2};
% 调用模型函数
[P_storage, P_discard, P_ap_ac, lianhegonglv, p_xian] = calculate_AG_control(P_load, data, nigue, nique, guangfus, beilv, loss_factor);
% 显示结果
disp('充放电功率:');
disp(P_storage);
disp('弃电功率:');
disp(P_discard);
disp('电网调度功率限幅:');
disp(P_ap_ac);
disp('联合运行的输出功率:');
disp(lianhegonglv);
disp('p_xian:');
disp(p_xian);