How to solve the error for graph?

6 次查看(过去 30 天)
Minhee
Minhee 2024-1-16
num_simulations = 10000;
%Common parameters
Discount_Rate_min = 0.06; % assume 6-8%
Discount_Rate_max = 0.08;
Discount_Rate_values = unifrnd(Discount_Rate_min, Discount_Rate_max, [num_simulations, 1]);
Lifetime = 20; % years
% Define electricity costs
electricity_cost_AT = 0.261;
electricity_cost_BE = 0.245;
electricity_cost_BG = 0.253;
electricity_cost_CZ = 0.247;
electricity_cost_DE_LU = 0.235;
electricity_cost_DK = 0.215;
electricity_cost_EE = 0.193;
electricity_cost_ES = 0.168;
electricity_cost_FI = 0.154;
electricity_cost_FR = 0.276;
electricity_cost_GR = 0.280;
electricity_cost_HR = 0.272;
electricity_cost_HU = 0.272;
electricity_cost_IE = 0.223;
electricity_cost_IT = 0.312;
electricity_cost_LT = 0.230;
electricity_cost_LV = 0.227;
electricity_cost_NL = 0.242;
electricity_cost_PL = 0.167;
electricity_cost_PT = 0.168;
electricity_cost_RO = 0.265;
electricity_cost_SE = 0.101;
electricity_cost_SI = 0.274;
electricity_cost_SK = 0.265;
% Create a structure for electricity costs
electricity_costs = struct(...
'AT', electricity_cost_AT, ...
'BE', electricity_cost_BE, ...
'BG', electricity_cost_BG, ...
'CZ', electricity_cost_CZ, ...
'DE_LU', electricity_cost_DE_LU, ...
'DK', electricity_cost_DK, ...
'EE', electricity_cost_EE, ...
'ES', electricity_cost_ES, ...
'FI', electricity_cost_FI, ...
'FR', electricity_cost_FR, ...
'GR', electricity_cost_GR, ...
'HR', electricity_cost_HR, ...
'HU', electricity_cost_HU, ...
'IE', electricity_cost_IE, ...
'IT', electricity_cost_IT, ...
'LT', electricity_cost_LT, ...
'LV', electricity_cost_LV, ...
'NL', electricity_cost_NL, ...
'PL', electricity_cost_PL, ...
'PT', electricity_cost_PT, ...
'RO', electricity_cost_RO, ...
'SE', electricity_cost_SE, ...
'SI', electricity_cost_SI, ...
'SK', electricity_cost_SK ...
);
FLH = [0,289,584,1392,2326,3371,4789,5711,6414,6945,7362,7733,8045,8261,8437,8559,8627,8667,8707,8723,8747,8755,8758,8760];
LHV = 33.33; %kWh/kgH2
%SOEC parameters
CAPEX_System_SOEC_mean = 4200; %$/kW
CAPEX_System_SOEC_std = 500;
CAPEX_System_SOEC_values = normrnd(CAPEX_System_SOEC_mean, CAPEX_System_SOEC_std, [num_simulations,1]);
CAPEX_System_SOEC_values(CAPEX_System_SOEC_values < 2800) = 2800;
CAPEX_System_SOEC_values(CAPEX_System_SOEC_values > 5600) = 5600;
%CAPEX_Stack_SOEC_values = 0.5*CAPEX_System_SOEC_values; % 50% of CAPEX system
CAPEX_SOEC_values = CAPEX_System_SOEC_values;
OPEX_SOEC_values = 3; % 3% of CAPEX/a
System_Efficiency_SOEC_mean = 0.775;
System_Efficiency_SOEC_std = 0.05;
System_Efficiency_SOEC_values = normrnd(System_Efficiency_SOEC_mean, System_Efficiency_SOEC_std, [num_simulations,1]);
System_Efficiency_SOEC_values(System_Efficiency_SOEC_values < 0.74) = 0.74;
System_Efficiency_SOEC_values(System_Efficiency_SOEC_values > 0.81) = 0.81;
% Define the cell array of country codes
countries = {'DE', 'SE', 'AT', 'BE', 'BG', 'CZ', 'DK', 'EE', 'ES', 'FI', 'FR', 'GR', 'HR', 'HU', 'IE', 'IT', 'LT', 'LV', 'NL', 'PL', 'PT', 'RO', 'SI', 'SK'};
% Calculate SOEC LCOH values
term1_S = LHV ./ (System_Efficiency_SOEC_values);
term2_S = Discount_Rate_values .* (1 + Discount_Rate_values).^Lifetime;
term3_S = (OPEX_SOEC_values / 100);
term4_S = CAPEX_SOEC_values ./ FLH;
% Initialize an array to store LCOH values for each simulation and country
LCOH_SOEC = zeros(num_simulations, 24);
% Loop through each simulation and calculate LCOH for each country
for sim = 1:num_simulations
for country_idx = 1:24
country_code = countries{country_idx}; % Assuming 'DE', 'SE', 'AT', ...
electricity_cost_country = electricity_costs.(country_code);
% Calculate LCOH for the current simulation and country
LCOH_SOEC(sim, country_idx) = term1_S(sim) * ((term2_S(sim) / ((1 + Discount_Rate_values(sim))^Lifetime - 1) + term3_S) * term4_S(sim) + electricity_cost_country);
end
end
Unrecognized field name "DE".
% Average values of LCOH for each country
avg_LCOH_SOEC = mean(LCOH_SOEC);
% Plot LCOH values for each country
figure;
hold on;
% Loop through each country and plot LCOH as a line
for country_idx = 1:24
country_code = countries{country_idx};
plot(FLH, avg_LCOH_SOEC(:, country_idx), '--', 'DisplayName', ['AVG_' country_code], 'LineWidth', 2);
end
hold off;
% Customize the plot
title('LCOH vs FLH Comparison for Each Country');
xlabel('FLH (Full Load Hours)');
ylabel('LCOH (Levelized Cost of Hydrogen)');
legend('Location', 'best');
grid on;
I would like to compare avg_LCOH of each country (24 countries) in one graph.
Unrecognized field name "DE".
Error in S1_SOEC_2020 (line 109)
electricity_cost_country = electricity_costs.(country_code);
How to solve this error and plot the graph?
Please let me know the command.

回答(3 个)

Sam Chak
Sam Chak 2024-1-16
There are missing characters. From your code, it should be 'DE_LU'.
num_simulations = 10000;
%Common parameters
Discount_Rate_min = 0.06; % assume 6-8%
Discount_Rate_max = 0.08;
Discount_Rate_values = unifrnd(Discount_Rate_min, Discount_Rate_max, [num_simulations, 1]);
Lifetime = 20; % years
% Define electricity costs
electricity_cost_AT = 0.261;
electricity_cost_BE = 0.245;
electricity_cost_BG = 0.253;
electricity_cost_CZ = 0.247;
electricity_cost_DE_LU = 0.235;
electricity_cost_DK = 0.215;
electricity_cost_EE = 0.193;
electricity_cost_ES = 0.168;
electricity_cost_FI = 0.154;
electricity_cost_FR = 0.276;
electricity_cost_GR = 0.280;
electricity_cost_HR = 0.272;
electricity_cost_HU = 0.272;
electricity_cost_IE = 0.223;
electricity_cost_IT = 0.312;
electricity_cost_LT = 0.230;
electricity_cost_LV = 0.227;
electricity_cost_NL = 0.242;
electricity_cost_PL = 0.167;
electricity_cost_PT = 0.168;
electricity_cost_RO = 0.265;
electricity_cost_SE = 0.101;
electricity_cost_SI = 0.274;
electricity_cost_SK = 0.265;
% Create a structure for electricity costs
electricity_costs = struct(...
'AT', electricity_cost_AT, ...
'BE', electricity_cost_BE, ...
'BG', electricity_cost_BG, ...
'CZ', electricity_cost_CZ, ...
'DE_LU', electricity_cost_DE_LU, ...
'DK', electricity_cost_DK, ...
'EE', electricity_cost_EE, ...
'ES', electricity_cost_ES, ...
'FI', electricity_cost_FI, ...
'FR', electricity_cost_FR, ...
'GR', electricity_cost_GR, ...
'HR', electricity_cost_HR, ...
'HU', electricity_cost_HU, ...
'IE', electricity_cost_IE, ...
'IT', electricity_cost_IT, ...
'LT', electricity_cost_LT, ...
'LV', electricity_cost_LV, ...
'NL', electricity_cost_NL, ...
'PL', electricity_cost_PL, ...
'PT', electricity_cost_PT, ...
'RO', electricity_cost_RO, ...
'SE', electricity_cost_SE, ...
'SI', electricity_cost_SI, ...
'SK', electricity_cost_SK ...
);
FLH = [0,289,584,1392,2326,3371,4789,5711,6414,6945,7362,7733,8045,8261,8437,8559,8627,8667,8707,8723,8747,8755,8758,8760];
LHV = 33.33; %kWh/kgH2
%SOEC parameters
CAPEX_System_SOEC_mean = 4200; %$/kW
CAPEX_System_SOEC_std = 500;
CAPEX_System_SOEC_values = normrnd(CAPEX_System_SOEC_mean, CAPEX_System_SOEC_std, [num_simulations,1]);
CAPEX_System_SOEC_values(CAPEX_System_SOEC_values < 2800) = 2800;
CAPEX_System_SOEC_values(CAPEX_System_SOEC_values > 5600) = 5600;
%CAPEX_Stack_SOEC_values = 0.5*CAPEX_System_SOEC_values; % 50% of CAPEX system
CAPEX_SOEC_values = CAPEX_System_SOEC_values;
OPEX_SOEC_values = 3; % 3% of CAPEX/a
System_Efficiency_SOEC_mean = 0.775;
System_Efficiency_SOEC_std = 0.05;
System_Efficiency_SOEC_values = normrnd(System_Efficiency_SOEC_mean, System_Efficiency_SOEC_std, [num_simulations,1]);
System_Efficiency_SOEC_values(System_Efficiency_SOEC_values < 0.74) = 0.74;
System_Efficiency_SOEC_values(System_Efficiency_SOEC_values > 0.81) = 0.81;
% Define the cell array of country codes
countries = {'DE_LU', 'SE', 'AT', 'BE', 'BG', 'CZ', 'DK', 'EE', 'ES', 'FI', 'FR', 'GR', 'HR', 'HU', 'IE', 'IT', 'LT', 'LV', 'NL', 'PL', 'PT', 'RO', 'SI', 'SK'};
%% missing ^^^
% Calculate SOEC LCOH values
term1_S = LHV ./ (System_Efficiency_SOEC_values);
term2_S = Discount_Rate_values .* (1 + Discount_Rate_values).^Lifetime;
term3_S = (OPEX_SOEC_values / 100);
term4_S = CAPEX_SOEC_values ./ FLH;
% Initialize an array to store LCOH values for each simulation and country
LCOH_SOEC = zeros(num_simulations, 24);
% Loop through each simulation and calculate LCOH for each country
for sim = 1:num_simulations
for country_idx = 1:24
country_code = countries{country_idx}; % Assuming 'DE', 'SE', 'AT', ...
electricity_cost_country = electricity_costs.(country_code);
% Calculate LCOH for the current simulation and country
LCOH_SOEC(sim, country_idx) = term1_S(sim) * ((term2_S(sim) / ((1 + Discount_Rate_values(sim))^Lifetime - 1) + term3_S) * term4_S(sim) + electricity_cost_country);
end
end
% Average values of LCOH for each country
avg_LCOH_SOEC = mean(LCOH_SOEC);
% Plot LCOH values for each country
figure;
hold on;
% Loop through each country and plot LCOH as a line
for country_idx = 1:24
country_code = countries{country_idx};
plot(FLH, avg_LCOH_SOEC(:, country_idx), '--', 'DisplayName', ['AVG_' country_code], 'LineWidth', 2);
end
hold off;
% Customize the plot
title('LCOH vs FLH Comparison for Each Country');
xlabel('FLH (Full Load Hours)');
ylabel('LCOH (Levelized Cost of Hydrogen)');
legend('Location', 'best');
Warning: Limiting legend entries to 50. Specify a vector of graphics objects to display more than 50 entries.
grid on;

Hassaan
Hassaan 2024-1-16
The error you're encountering, "Unrecognized field name 'DE'", suggests that the field 'DE' does not exist in the electricity_costs structure. However, I notice in the code you've provided, 'DE' is not explicitly defined in the electricity_costs structure, but 'DE_LU' is. It's possible that you meant to use 'DE_LU' instead of 'DE' in your countries array.
To fix this error, you should either add 'DE' to your electricity_costs structure or use 'DE_LU' in your countries array, depending on which one correctly represents the data you're working with.
Here's how you can modify the countries array if you intend to use 'DE_LU':
num_simulations = 10000;
%Common parameters
Discount_Rate_min = 0.06; % assume 6-8%
Discount_Rate_max = 0.08;
Discount_Rate_values = unifrnd(Discount_Rate_min, Discount_Rate_max, [num_simulations, 1]);
Lifetime = 20; % years
% Define electricity costs
electricity_cost_AT = 0.261;
electricity_cost_BE = 0.245;
electricity_cost_BG = 0.253;
electricity_cost_CZ = 0.247;
electricity_cost_DE_LU = 0.235;
electricity_cost_DK = 0.215;
electricity_cost_EE = 0.193;
electricity_cost_ES = 0.168;
electricity_cost_FI = 0.154;
electricity_cost_FR = 0.276;
electricity_cost_GR = 0.280;
electricity_cost_HR = 0.272;
electricity_cost_HU = 0.272;
electricity_cost_IE = 0.223;
electricity_cost_IT = 0.312;
electricity_cost_LT = 0.230;
electricity_cost_LV = 0.227;
electricity_cost_NL = 0.242;
electricity_cost_PL = 0.167;
electricity_cost_PT = 0.168;
electricity_cost_RO = 0.265;
electricity_cost_SE = 0.101;
electricity_cost_SI = 0.274;
electricity_cost_SK = 0.265;
% Create a structure for electricity costs
electricity_costs = struct(...
'AT', electricity_cost_AT, ...
'BE', electricity_cost_BE, ...
'BG', electricity_cost_BG, ...
'CZ', electricity_cost_CZ, ...
'DE_LU', electricity_cost_DE_LU, ...
'DK', electricity_cost_DK, ...
'EE', electricity_cost_EE, ...
'ES', electricity_cost_ES, ...
'FI', electricity_cost_FI, ...
'FR', electricity_cost_FR, ...
'GR', electricity_cost_GR, ...
'HR', electricity_cost_HR, ...
'HU', electricity_cost_HU, ...
'IE', electricity_cost_IE, ...
'IT', electricity_cost_IT, ...
'LT', electricity_cost_LT, ...
'LV', electricity_cost_LV, ...
'NL', electricity_cost_NL, ...
'PL', electricity_cost_PL, ...
'PT', electricity_cost_PT, ...
'RO', electricity_cost_RO, ...
'SE', electricity_cost_SE, ...
'SI', electricity_cost_SI, ...
'SK', electricity_cost_SK ...
);
FLH = [0,289,584,1392,2326,3371,4789,5711,6414,6945,7362,7733,8045,8261,8437,8559,8627,8667,8707,8723,8747,8755,8758,8760];
LHV = 33.33; %kWh/kgH2
%SOEC parameters
CAPEX_System_SOEC_mean = 4200; %$/kW
CAPEX_System_SOEC_std = 500;
CAPEX_System_SOEC_values = normrnd(CAPEX_System_SOEC_mean, CAPEX_System_SOEC_std, [num_simulations,1]);
CAPEX_System_SOEC_values(CAPEX_System_SOEC_values < 2800) = 2800;
CAPEX_System_SOEC_values(CAPEX_System_SOEC_values > 5600) = 5600;
%CAPEX_Stack_SOEC_values = 0.5*CAPEX_System_SOEC_values; % 50% of CAPEX system
CAPEX_SOEC_values = CAPEX_System_SOEC_values;
OPEX_SOEC_values = 3; % 3% of CAPEX/a
System_Efficiency_SOEC_mean = 0.775;
System_Efficiency_SOEC_std = 0.05;
System_Efficiency_SOEC_values = normrnd(System_Efficiency_SOEC_mean, System_Efficiency_SOEC_std, [num_simulations,1]);
System_Efficiency_SOEC_values(System_Efficiency_SOEC_values < 0.74) = 0.74;
System_Efficiency_SOEC_values(System_Efficiency_SOEC_values > 0.81) = 0.81;
% Define the cell array of country codes
countries = {'DE_LU', 'SE', 'AT', 'BE', 'BG', 'CZ', 'DK', 'EE', 'ES', 'FI', 'FR', 'GR', 'HR', 'HU', 'IE', 'IT', 'LT', 'LV', 'NL', 'PL', 'PT', 'RO', 'SI', 'SK'};
% Calculate SOEC LCOH values
term1_S = LHV ./ (System_Efficiency_SOEC_values);
term2_S = Discount_Rate_values .* (1 + Discount_Rate_values).^Lifetime;
term3_S = (OPEX_SOEC_values / 100);
term4_S = CAPEX_SOEC_values ./ FLH;
% Initialize an array to store LCOH values for each simulation and country
LCOH_SOEC = zeros(num_simulations, 24);
% Loop through each simulation and calculate LCOH for each country
for sim = 1:num_simulations
for country_idx = 1:24
country_code = countries{country_idx}; % Assuming 'DE', 'SE', 'AT', ...
electricity_cost_country = electricity_costs.(country_code);
% Calculate LCOH for the current simulation and country
LCOH_SOEC(sim, country_idx) = term1_S(sim) * ((term2_S(sim) / ((1 + Discount_Rate_values(sim))^Lifetime - 1) + term3_S) * term4_S(sim) + electricity_cost_country);
end
end
% Average values of LCOH for each country
avg_LCOH_SOEC = mean(LCOH_SOEC);
% Plot LCOH values for each country
figure;
hold on;
% Loop through each country and plot the average LCOH
for country_idx = 1:length(countries)
country_code = countries{country_idx};
plot(avg_LCOH_SOEC(country_idx), 'o-', 'DisplayName', country_code, 'LineWidth', 2);
end
hold off;
% Customize the plot
title('Average LCOH for Each Country');
xlabel('Country Index');
ylabel('LCOH (Levelized Cost of Hydrogen)');
legend('Location', 'best');
grid on;
In this revised code, each country's average LCOH is plotted as a point on the graph, with the country index on the x-axis and the LCOH on the y-axis. This will give you a comparative view of the LCOH across the 24 countries.
------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
Professional Interests
  • Technical Services and Consulting
  • Embedded Systems | Firmware Developement | Simulations
  • Electrical and Electronics Engineering
Feel free to contact me.
  1 个评论
Minhee
Minhee 2024-1-16
Thank you!
But X axis should be FLH (0~8760).
How can I change the graph?
% Calculate SOEC LCOH values
term1_S = LHV ./ (System_Efficiency_SOEC_values);
term2_S = Discount_Rate_values .* (1 + Discount_Rate_values).^Lifetime;
term3_S = (OPEX_SOEC_values / 100);
term4_S = CAPEX_SOEC_values ./ FLH;
% Initialize an array to store LCOH values for each simulation and country
LCOH_SOEC = zeros(num_simulations, 24);
% Loop through each simulation and calculate LCOH for each country
for sim = 1:num_simulations
for country_idx = 1:24
country_code = countries{country_idx}; % Assuming 'DE', 'SE', 'AT', ...
electricity_cost_country = electricity_costs.(country_code);
% Calculate LCOH for the current simulation and country
LCOH_SOEC(sim, country_idx) = term1_S(sim) * ((term2_S(sim) / ((1 + Discount_Rate_values(sim))^Lifetime - 1) + term3_S) * term4_S(sim) + electricity_cost_country);
end
end
% Calculate the average LCOH for each country across simulations
average_LCOH_SOEC = mean(LCOH_SOEC);
% Plot the line graph for each country using the average LCOH
figure;
for country_idx = 1:24
country_code = countries{country_idx};
plot(FLH, average_LCOH_SOEC(:, country_idx)*ones(size(FLH)), 'o-', 'DisplayName', country_code);
hold on;
end
xlabel('FLH (Full Load Hours)');
ylabel('Average LCOH (Levelized Cost of Hydrogen)');
title('Average LCOH vs FLH for 24 Countries');
legend('Location', 'Best');
grid on;
It's my code but nothing in the graph and FLH is not 0~8760 even though I defined the FLH.

请先登录,再进行评论。


Star Strider
Star Strider 2024-1-16
I tweaked your code a bit, however it is still incorrect.
The main problem is that ‘avg_LCOH_SOEC’ should be a (24x24) matrix (24 countries and 24 ‘FLH’ units). Then it would work as you want it to. It is instead a (1x24) vector, and that means the plot is plotting points, not vectors (so I changed it to plot markers). I cannot follow what you are doing, so I leave that to you to solve. (The only reason it plots at all is that the number of countries is the same as the length of ‘FLH’.)
The other problem is that ‘FLH’ has as its first element 0 so:
term4_S = CAPEX_SOEC_values ./ FLH;
and so ‘term4_S’ was infinite. That created a matrix of ‘Inf’ and that is the reason the plot was empty. (I added 1 to ‘FLH’ to solve that problem temporarily. Change that so that it does what you want it to.)
This is my slightly edited version of your posted code. It runs and produces a plot, however it needs help to work as you want it to, and only you can provide that for it.
The edited code —
num_simulations = 10000;
%Common parameters
Discount_Rate_min = 0.06; % assume 6-8%
Discount_Rate_max = 0.08;
Discount_Rate_values = unifrnd(Discount_Rate_min, Discount_Rate_max, [num_simulations, 1]);
Lifetime = 20; % years
% Define electricity costs
electricity_cost_AT = 0.261;
electricity_cost_BE = 0.245;
electricity_cost_BG = 0.253;
electricity_cost_CZ = 0.247;
electricity_cost_DE_LU = 0.235;
electricity_cost_DK = 0.215;
electricity_cost_EE = 0.193;
electricity_cost_ES = 0.168;
electricity_cost_FI = 0.154;
electricity_cost_FR = 0.276;
electricity_cost_GR = 0.280;
electricity_cost_HR = 0.272;
electricity_cost_HU = 0.272;
electricity_cost_IE = 0.223;
electricity_cost_IT = 0.312;
electricity_cost_LT = 0.230;
electricity_cost_LV = 0.227;
electricity_cost_NL = 0.242;
electricity_cost_PL = 0.167;
electricity_cost_PT = 0.168;
electricity_cost_RO = 0.265;
electricity_cost_SE = 0.101;
electricity_cost_SI = 0.274;
electricity_cost_SK = 0.265;
% Create a structure for electricity costs
electricity_costs = struct(...
'AT', electricity_cost_AT, ...
'BE', electricity_cost_BE, ...
'BG', electricity_cost_BG, ...
'CZ', electricity_cost_CZ, ...
'DE_LU', electricity_cost_DE_LU, ...
'DK', electricity_cost_DK, ...
'EE', electricity_cost_EE, ...
'ES', electricity_cost_ES, ...
'FI', electricity_cost_FI, ...
'FR', electricity_cost_FR, ...
'GR', electricity_cost_GR, ...
'HR', electricity_cost_HR, ...
'HU', electricity_cost_HU, ...
'IE', electricity_cost_IE, ...
'IT', electricity_cost_IT, ...
'LT', electricity_cost_LT, ...
'LV', electricity_cost_LV, ...
'NL', electricity_cost_NL, ...
'PL', electricity_cost_PL, ...
'PT', electricity_cost_PT, ...
'RO', electricity_cost_RO, ...
'SE', electricity_cost_SE, ...
'SI', electricity_cost_SI, ...
'SK', electricity_cost_SK ...
);
FLH = [0,289,584,1392,2326,3371,4789,5711,6414,6945,7362,7733,8045,8261,8437,8559,8627,8667,8707,8723,8747,8755,8758,8760];
LHV = 33.33; %kWh/kgH2
%SOEC parameters
CAPEX_System_SOEC_mean = 4200; %$/kW
CAPEX_System_SOEC_std = 500;
CAPEX_System_SOEC_values = normrnd(CAPEX_System_SOEC_mean, CAPEX_System_SOEC_std, [num_simulations,1]);
CAPEX_System_SOEC_values(CAPEX_System_SOEC_values < 2800) = 2800;
CAPEX_System_SOEC_values(CAPEX_System_SOEC_values > 5600) = 5600;
%CAPEX_Stack_SOEC_values = 0.5*CAPEX_System_SOEC_values; % 50% of CAPEX system
CAPEX_SOEC_values = CAPEX_System_SOEC_values;
OPEX_SOEC_values = 3; % 3% of CAPEX/a
System_Efficiency_SOEC_mean = 0.775;
System_Efficiency_SOEC_std = 0.05;
System_Efficiency_SOEC_values = normrnd(System_Efficiency_SOEC_mean, System_Efficiency_SOEC_std, [num_simulations,1]);
System_Efficiency_SOEC_values(System_Efficiency_SOEC_values < 0.74) = 0.74;
System_Efficiency_SOEC_values(System_Efficiency_SOEC_values > 0.81) = 0.81;
% Define the cell array of country codes
countries = {'DE_LU', 'SE', 'AT', 'BE', 'BG', 'CZ', 'DK', 'EE', 'ES', 'FI', 'FR', 'GR', 'HR', 'HU', 'IE', 'IT', 'LT', 'LV', 'NL', 'PL', 'PT', 'RO', 'SI', 'SK'};
% Calculate SOEC LCOH values
term1_S = LHV ./ (System_Efficiency_SOEC_values);
term2_S = Discount_Rate_values .* (1 + Discount_Rate_values).^Lifetime;
term3_S = (OPEX_SOEC_values / 100);
FLH = FLH + 1; % <-ADDED
term4_S = CAPEX_SOEC_values ./ FLH;
% Initialize an array to store LCOH values for each simulation and country
LCOH_SOEC = zeros(num_simulations, 24);
% Loop through each simulation and calculate LCOH for each country
for sim = 1:num_simulations
for country_idx = 1:24
country_code = countries{country_idx}; % Assuming 'DE', 'SE', 'AT', ...
electricity_cost_country = electricity_costs.(country_code);
% Calculate LCOH for the current simulation and country
% QCI = [sim term1_S(sim) term2_S(sim) ((1 + Discount_Rate_values(sim))^Lifetime - 1) term3_S term4_S(sim) electricity_cost_country]
LCOH_SOEC(sim, country_idx) = term1_S(sim) .* ((term2_S(sim) ./ ((1 + Discount_Rate_values(sim)).^Lifetime - 1) + term3_S) * term4_S(sim) + electricity_cost_country);
end
end
% Average values of LCOH for each country
SzLCOH_SOEC = size(LCOH_SOEC)
SzLCOH_SOEC = 1×2
10000 24
avg_LCOH_SOEC = mean(LCOH_SOEC)
avg_LCOH_SOEC = 1×24
1.0e+04 * 2.2530 2.2524 2.2531 2.2530 2.2531 2.2530 2.2529 2.2528 2.2527 2.2526 2.2532 2.2532 2.2531 2.2531 2.2529 2.2533 2.2530 2.2529 2.2530 2.2527 2.2527 2.2531 2.2531 2.2531
% Plot LCOH values for each country
figure;
hold on;
% Loop through each country and plot LCOH as a line
for country_idx = 1:24
country_code = countries{country_idx};
country_code = strrep(country_code, '_', '\_');
plot(FLH, avg_LCOH_SOEC(:,country_idx), '_', 'DisplayName', ["AVG\_" + string(country_code)], 'LineWidth', 2);
end
hold off;
% Customize the plot
title('LCOH vs FLH Comparison for Each Country');
xlabel('FLH (Full Load Hours)');
ylabel('LCOH (Levelized Cost of Hydrogen)');
legend('Location', 'bestoutside', 'NumColumns',2);
Warning: Limiting legend entries to 50. Specify a vector of graphics objects to display more than 50 entries.
grid on;
.
  4 个评论
Minhee
Minhee 2024-1-16
The result graph should be like the above image.
But I don't know the command for it.
Star Strider
Star Strider 2024-1-16
You need to create the (24 x 24) matrix. First, create a (10000 x 24 x 24) matrix representing (simulations x countries x FLH) or some permutation of that, and then calculate the mean over the dimension that represents the number of simulations to get the necessary matrix for the plot. After that, the plot should be straightforward.
I cannot figure out what you are doing, so I cannot help with that part of it.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Simulation and Analysis 的更多信息

标签

产品


版本

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by