How to change the graph type
조회 수: 4 (최근 30일)
이전 댓글 표시
I would like to change a type of graph.
Code is;
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
Electricity_Cost_mean = 0.255; %EUR/kWh
Electricity_Cost_std = 0.04;
Electricity_Cost_values = normrnd(Electricity_Cost_mean, Electricity_Cost_std, [num_simulations,1]);
Electricity_Cost_values(Electricity_Cost_values < 0.02) = 0.02;
Electricity_Cost_values(Electricity_Cost_values > 0.9) = 0.9;
FLH_min = 1000;
FLH_max = 8760;
FLH = unifrnd(FLH_min, FLH_max, [num_simulations, 1]);
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 + CAPEX_Stack_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;
%PEM parameters
CAPEX_System_PEM_mean = 1450; %$/kW
CAPEX_System_PEM_std = 50;
CAPEX_System_PEM_values = normrnd(CAPEX_System_PEM_mean, CAPEX_System_PEM_std, [num_simulations,1]);
CAPEX_System_PEM_values(CAPEX_System_PEM_values < 1100) = 1100;
CAPEX_System_PEM_values(CAPEX_System_PEM_values > 1800) = 1800;
CAPEX_Stack_PEM_values = 0.35*CAPEX_System_PEM_values; % 35% of CAPEX system
CAPEX_PEM_values = (CAPEX_System_PEM_values + CAPEX_Stack_PEM_values);
OPEX_PEM_values = 3;
System_Efficiency_PEM_mean = 0.58;
System_Efficiency_PEM_std = 0.01;
System_Efficiency_PEM_values = normrnd(System_Efficiency_PEM_mean, System_Efficiency_PEM_std, [num_simulations,1]);
System_Efficiency_PEM_values(System_Efficiency_PEM_values < 0.56) = 0.56;
System_Efficiency_PEM_values(System_Efficiency_PEM_values > 0.6) = 0.6;
%AEC parameters
CAPEX_System_AEC_mean = 950; % $/kW
CAPEX_System_AEC_std = 50;
CAPEX_System_AEC_values = normrnd(CAPEX_System_AEC_mean, CAPEX_System_AEC_std, [num_simulations,1]);
CAPEX_System_AEC_values(CAPEX_System_AEC_values < 500) = 500;
CAPEX_System_AEC_values(CAPEX_System_AEC_values > 1400) = 1400;
CAPEX_Stack_AEC_values = 0.35*CAPEX_System_AEC_values; % 35% of CAPEX system
CAPEX_AEC_values = (CAPEX_System_AEC_values + CAPEX_Stack_AEC_values);
OPEX_AEC_values = 3;
System_Efficiency_AEC_mean = 0.665;
System_Efficiency_AEC_std = 0.05;
System_Efficiency_AEC_values = normrnd(System_Efficiency_AEC_mean, System_Efficiency_AEC_std, [num_simulations,1]);
System_Efficiency_AEC_values(System_Efficiency_AEC_values < 0.63) = 0.63;
System_Efficiency_AEC_values(System_Efficiency_AEC_values > 0.7) = 0.7;
% 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;
LCOH_SOEC = term1_S .* ((term2_S ./ ((1 + Discount_Rate_values).^Lifetime - 1) + term3_S) .* term4_S + Electricity_Cost_values);
% Calculate PEM LCOH values
term1_P = LHV ./ (System_Efficiency_PEM_values);
term2_P = Discount_Rate_values .* (1 + Discount_Rate_values).^Lifetime;
term3_P = (OPEX_PEM_values / 100);
term4_P = CAPEX_PEM_values ./ FLH;
LCOH_PEM = term1_P .* ((term2_P ./ ((1 + Discount_Rate_values).^Lifetime - 1) + term3_P) .* term4_P + Electricity_Cost_values);
% Calculate AEC LCOH values
term1_A = LHV ./ (System_Efficiency_AEC_values);
term2_A = Discount_Rate_values .* (1 + Discount_Rate_values).^Lifetime;
term3_A = (OPEX_AEC_values / 100);
term4_A = CAPEX_AEC_values ./ FLH;
LCOH_AEC = term1_A .* ((term2_A ./ ((1 + Discount_Rate_values).^Lifetime - 1) + term3_A) .* term4_A + Electricity_Cost_values);
% Calculate mean and standard deviation of Electricity_Cost_values
electricity_cost_mean = mean(Electricity_Cost_values);
electricity_cost_std = std(Electricity_Cost_values);
% Define the 3-sigma range
lower_limit = electricity_cost_mean - 3 * electricity_cost_std;
upper_limit = electricity_cost_mean + 3 * electricity_cost_std;
% Filter data based on the 3-sigma range
valid_indices = (Electricity_Cost_values >= lower_limit) & (Electricity_Cost_values <= upper_limit);
FLH_filtered = FLH(valid_indices);
LCOH_SOEC_filtered = LCOH_SOEC(valid_indices);
LCOH_PEM_filtered = LCOH_PEM(valid_indices);
LCOH_AEC_filtered = LCOH_AEC(valid_indices);
% Calculate mean and standard deviation of Electricity_Cost_values
electricity_cost_mean = mean(Electricity_Cost_values);
electricity_cost_std = std(Electricity_Cost_values);
% Define the 3-sigma range
lower_limit = electricity_cost_mean - 3 * electricity_cost_std;
upper_limit = electricity_cost_mean + 3 * electricity_cost_std;
% Filter data based on the 3-sigma range
valid_indices = (Electricity_Cost_values >= lower_limit) & (Electricity_Cost_values <= upper_limit);
FLH_filtered = FLH(valid_indices);
LCOH_SOEC_filtered = LCOH_SOEC(valid_indices);
LCOH_PEM_filtered = LCOH_PEM(valid_indices);
LCOH_AEC_filtered = LCOH_AEC(valid_indices);
% Plot the graph
figure;
scatter(FLH_filtered, LCOH_SOEC_filtered, 'o', 'DisplayName', 'SOEC');
hold on;
scatter(FLH_filtered, LCOH_PEM_filtered, 'x', 'DisplayName', 'PEM');
scatter(FLH_filtered, LCOH_AEC_filtered, '+', 'DisplayName', 'AEC');
xlabel('FLH');
ylabel('LCOH');
title('3-Sigma Approach Graph');
legend('Location', 'best');
grid on;
hold off;
This graph is the result of the code but I need the graph like below one.
Please let me know the code for it.
댓글 수: 1
Steven Lord
2024년 1월 5일
Just a comment, you have a number of blocks of code that look awfully similar aside from using different variable names for the data. For example:
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;
Rather than duplicating all that code, I'd consider creating a function that accepts the desired mean and std values, generates the data, and returns it to its caller. [I'm not exactly sure how you generate your lower and upper bounds; I suspect it's some number of standard deviations, but if they vary you could always accept the lower and upper bounds as additional inputs.]
function data = generateData(meanvalue, stdvalue, num_simulations)
LB = meanvalue - 3*stdvalue;
UB = meanvalue + 3*stdvalue;
data = normrnd(meanvalue, stdvalue, [num_simulations,1]);
data = min(max(data, LB), UB);
% or
%{
data(data < LB) = LB;
data(data > UB) = UB;
%}
Now instead of duplicating this code for CAPEX_System_SOEC_values, Electricity_Cost_values, System_Efficiency_SOEC_values, etc.you just call generateData once per variable. It would make your code a bit shorter and IMO easier to understand.
채택된 답변
Star Strider
2024년 1월 3일
I believe that this is reasonably close —
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
Electricity_Cost_mean = 0.255; %EUR/kWh
Electricity_Cost_std = 0.04;
Electricity_Cost_values = normrnd(Electricity_Cost_mean, Electricity_Cost_std, [num_simulations,1]);
Electricity_Cost_values(Electricity_Cost_values < 0.02) = 0.02;
Electricity_Cost_values(Electricity_Cost_values > 0.9) = 0.9;
FLH_min = 1000;
FLH_max = 8760;
FLH = unifrnd(FLH_min, FLH_max, [num_simulations, 1]);
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 + CAPEX_Stack_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;
%PEM parameters
CAPEX_System_PEM_mean = 1450; %$/kW
CAPEX_System_PEM_std = 50;
CAPEX_System_PEM_values = normrnd(CAPEX_System_PEM_mean, CAPEX_System_PEM_std, [num_simulations,1]);
CAPEX_System_PEM_values(CAPEX_System_PEM_values < 1100) = 1100;
CAPEX_System_PEM_values(CAPEX_System_PEM_values > 1800) = 1800;
CAPEX_Stack_PEM_values = 0.35*CAPEX_System_PEM_values; % 35% of CAPEX system
CAPEX_PEM_values = (CAPEX_System_PEM_values + CAPEX_Stack_PEM_values);
OPEX_PEM_values = 3;
System_Efficiency_PEM_mean = 0.58;
System_Efficiency_PEM_std = 0.01;
System_Efficiency_PEM_values = normrnd(System_Efficiency_PEM_mean, System_Efficiency_PEM_std, [num_simulations,1]);
System_Efficiency_PEM_values(System_Efficiency_PEM_values < 0.56) = 0.56;
System_Efficiency_PEM_values(System_Efficiency_PEM_values > 0.6) = 0.6;
%AEC parameters
CAPEX_System_AEC_mean = 950; % $/kW
CAPEX_System_AEC_std = 50;
CAPEX_System_AEC_values = normrnd(CAPEX_System_AEC_mean, CAPEX_System_AEC_std, [num_simulations,1]);
CAPEX_System_AEC_values(CAPEX_System_AEC_values < 500) = 500;
CAPEX_System_AEC_values(CAPEX_System_AEC_values > 1400) = 1400;
CAPEX_Stack_AEC_values = 0.35*CAPEX_System_AEC_values; % 35% of CAPEX system
CAPEX_AEC_values = (CAPEX_System_AEC_values + CAPEX_Stack_AEC_values);
OPEX_AEC_values = 3;
System_Efficiency_AEC_mean = 0.665;
System_Efficiency_AEC_std = 0.05;
System_Efficiency_AEC_values = normrnd(System_Efficiency_AEC_mean, System_Efficiency_AEC_std, [num_simulations,1]);
System_Efficiency_AEC_values(System_Efficiency_AEC_values < 0.63) = 0.63;
System_Efficiency_AEC_values(System_Efficiency_AEC_values > 0.7) = 0.7;
% 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;
LCOH_SOEC = term1_S .* ((term2_S ./ ((1 + Discount_Rate_values).^Lifetime - 1) + term3_S) .* term4_S + Electricity_Cost_values);
% Calculate PEM LCOH values
term1_P = LHV ./ (System_Efficiency_PEM_values);
term2_P = Discount_Rate_values .* (1 + Discount_Rate_values).^Lifetime;
term3_P = (OPEX_PEM_values / 100);
term4_P = CAPEX_PEM_values ./ FLH;
LCOH_PEM = term1_P .* ((term2_P ./ ((1 + Discount_Rate_values).^Lifetime - 1) + term3_P) .* term4_P + Electricity_Cost_values);
% Calculate AEC LCOH values
term1_A = LHV ./ (System_Efficiency_AEC_values);
term2_A = Discount_Rate_values .* (1 + Discount_Rate_values).^Lifetime;
term3_A = (OPEX_AEC_values / 100);
term4_A = CAPEX_AEC_values ./ FLH;
LCOH_AEC = term1_A .* ((term2_A ./ ((1 + Discount_Rate_values).^Lifetime - 1) + term3_A) .* term4_A + Electricity_Cost_values);
% Calculate mean and standard deviation of Electricity_Cost_values
electricity_cost_mean = mean(Electricity_Cost_values);
electricity_cost_std = std(Electricity_Cost_values);
% Define the 3-sigma range
lower_limit = electricity_cost_mean - 3 * electricity_cost_std;
upper_limit = electricity_cost_mean + 3 * electricity_cost_std;
% Filter data based on the 3-sigma range
valid_indices = (Electricity_Cost_values >= lower_limit) & (Electricity_Cost_values <= upper_limit);
FLH_filtered = FLH(valid_indices);
LCOH_SOEC_filtered = LCOH_SOEC(valid_indices);
LCOH_PEM_filtered = LCOH_PEM(valid_indices);
LCOH_AEC_filtered = LCOH_AEC(valid_indices);
% Calculate mean and standard deviation of Electricity_Cost_values
electricity_cost_mean = mean(Electricity_Cost_values);
electricity_cost_std = std(Electricity_Cost_values);
% Define the 3-sigma range
lower_limit = electricity_cost_mean - 3 * electricity_cost_std;
upper_limit = electricity_cost_mean + 3 * electricity_cost_std;
% Filter data based on the 3-sigma range
valid_indices = (Electricity_Cost_values >= lower_limit) & (Electricity_Cost_values <= upper_limit);
FLH_filtered = FLH(valid_indices);
[FLH_filtereds,sidx] = sort(FLH_filtered);
LCOH_SOEC_filtered = LCOH_SOEC(valid_indices);
LCOH_PEM_filtered = LCOH_PEM(valid_indices);
LCOH_AEC_filtered = LCOH_AEC(valid_indices);
LCOH_SOEC_filteredx = movmax(LCOH_SOEC_filtered(sidx), 100);
LCOH_SOEC_filteredn = movmin(LCOH_SOEC_filtered(sidx), 100);
Px1 = polyfit(FLH_filtereds, LCOH_SOEC_filteredx, 3);
Pn1 = polyfit(FLH_filtereds, LCOH_SOEC_filteredn, 3);
Fx1 = polyval(Px1, FLH_filtereds);
Fn1 = polyval(Pn1, FLH_filtereds);
LCOH_PEM_filteredx = movmax(LCOH_PEM_filtered(sidx), 100);
LCOH_PEM_filteredn = movmin(LCOH_PEM_filtered(sidx), 100);
Px2 = polyfit(FLH_filtereds, LCOH_PEM_filteredx, 3);
Pn2 = polyfit(FLH_filtereds, LCOH_PEM_filteredn, 3);
Fx2 = polyval(Px2, FLH_filtereds);
Fn2 = polyval(Pn2, FLH_filtereds);
LCOH_AEC_filteredx = movmax(LCOH_AEC_filtered(sidx), 100);
LCOH_AEC_filteredn = movmin(LCOH_AEC_filtered(sidx), 100);
Px3 = polyfit(FLH_filtereds, LCOH_AEC_filteredx, 3);
Pn3 = polyfit(FLH_filtereds, LCOH_AEC_filteredn, 3);
Fx3 = polyval(Px3, FLH_filtereds);
Fn3 = polyval(Pn3, FLH_filtereds);
% Plot the graph
figure;
hs{1} = scatter(FLH_filtered, LCOH_SOEC_filtered, 'o', 'DisplayName', 'SOEC');
hold on;
hs{2} = scatter(FLH_filtered, LCOH_PEM_filtered, 'x', 'DisplayName', 'PEM');
hs{3} = scatter(FLH_filtered, LCOH_AEC_filtered, '+', 'DisplayName', 'AEC');
hold off;
xlabel('FLH');
ylabel('LCOH');
title('3-Sigma Approach Graph');
legend([hs{:}], 'Location', 'best');
grid on;
figure;
hp{1} = patch([FLH_filtereds; flip(FLH_filtereds)], [Fx1; flip(Fn1)], 'r', 'EdgeColor','none', 'FAceAlpha',0.5, 'DisplayName', 'SOEC');
hold on;
hp{2} = patch([FLH_filtereds; flip(FLH_filtereds)], [Fx2; flip(Fn2)], 'g', 'EdgeColor','none', 'FAceAlpha',0.5, 'DisplayName', 'PEM');
hp{3} = patch([FLH_filtereds; flip(FLH_filtereds)], [Fx3; flip(Fn3)], 'b', 'EdgeColor','none', 'FAceAlpha',0.5, 'DisplayName', 'AEC');
hold off;
xlabel('FLH');
ylabel('LCOH');
title('3-Sigma Approach Graph');
legend([hp{:}], 'Location', 'best');
grid on;
I am not certain what result you want. This finds a moving maximum and minimum of every group of data (after sorting the independent variable in order to sort the others), and then does a simple 3-degree polynomial regression to provide a smooth upper and lower edge to the patch plots, and then draws the patch plots.
.
댓글 수: 7
Star Strider
2024년 1월 23일
I added the loglog plot just to see what iut would look like. You can delete it if you want to.
Try this —
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
electricity_cost_SE = [-0.002,0,0.001,0.001,0.002,0.003,0.003,0.004,0.005,0.006,0.007,0.01,0.013,0.017,0.021,0.026,0.031,0.036,0.04,0.046,0.051,0.057,0.063,0.07,0.079,0.091,0.101];
FLH = [0,100,200,300,400,500,600,700,800,900,1000,1500,2000,2500,3000,3500,4000,4500,5000,5500,6000,6500,7000,7500,8000,8500,8760];
LHV = 33.33; %kWh/kgH2
% Create a table
dataTable_SE = table(FLH', electricity_cost_SE', 'VariableNames', {'FLH', 'electricity_cost_SE'});
%SOEC parameters
CAPEX_System_SOEC_mean = 4200; %$/kW
CAPEX_System_SOEC_std = 1142.7;
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.0408;
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;
%PEM parameters
CAPEX_System_PEM_mean = 1450; %$/kW
CAPEX_System_PEM_std = 367.42;
CAPEX_System_PEM_values = normrnd(CAPEX_System_PEM_mean, CAPEX_System_PEM_std, [num_simulations,1]);
CAPEX_System_PEM_values(CAPEX_System_PEM_values < 1100) = 1100;
CAPEX_System_PEM_values(CAPEX_System_PEM_values > 1800) = 1800;
%CAPEX_Stack_PEM_values = 0.35*CAPEX_System_PEM_values; % 35% of CAPEX system
CAPEX_PEM_values = CAPEX_System_PEM_values;
OPEX_PEM_values = 3;
System_Efficiency_PEM_mean = 0.58;
System_Efficiency_PEM_std = 0.0163;
System_Efficiency_PEM_values = normrnd(System_Efficiency_PEM_mean, System_Efficiency_PEM_std, [num_simulations,1]);
System_Efficiency_PEM_values(System_Efficiency_PEM_values < 0.56) = 0.56;
System_Efficiency_PEM_values(System_Efficiency_PEM_values > 0.6) = 0.6;
%AEC parameters
CAPEX_System_AEC_mean = 950; % $/kW
CAPEX_System_AEC_std = 387.3;
CAPEX_System_AEC_values = normrnd(CAPEX_System_AEC_mean, CAPEX_System_AEC_std, [num_simulations,1]);
CAPEX_System_AEC_values(CAPEX_System_AEC_values < 500) = 500;
CAPEX_System_AEC_values(CAPEX_System_AEC_values > 1400) = 1400;
%CAPEX_Stack_AEC_values = 0.35*CAPEX_System_AEC_values; % 35% of CAPEX system
CAPEX_AEC_values = CAPEX_System_AEC_values;
OPEX_AEC_values = 3;
System_Efficiency_AEC_mean = 0.665;
System_Efficiency_AEC_std = 0.0271;
System_Efficiency_AEC_values = normrnd(System_Efficiency_AEC_mean, System_Efficiency_AEC_std, [num_simulations,1]);
System_Efficiency_AEC_values(System_Efficiency_AEC_values < 0.63) = 0.63;
System_Efficiency_AEC_values(System_Efficiency_AEC_values > 0.7) = 0.7;
% 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;
LCOH_SOEC = term1_S .* ((term2_S ./ ((1 + Discount_Rate_values).^Lifetime - 1) + term3_S) .* term4_S + electricity_cost_SE);
% Calculate PEM LCOH values
term1_P = LHV ./ System_Efficiency_PEM_values;
term2_P = Discount_Rate_values .* (1 + Discount_Rate_values).^Lifetime;
term3_P = (OPEX_PEM_values / 100);
term4_P = CAPEX_PEM_values ./ FLH;
LCOH_PEM = term1_P .* ((term2_P ./ ((1 + Discount_Rate_values).^Lifetime - 1) + term3_P) .* term4_P + electricity_cost_SE);
% Calculate AEC LCOH values
term1_A = LHV ./ System_Efficiency_AEC_values;
term2_A = Discount_Rate_values .* (1 + Discount_Rate_values).^Lifetime;
term3_A = (OPEX_AEC_values / 100);
term4_A = CAPEX_AEC_values ./ FLH;
LCOH_AEC = term1_A .* ((term2_A ./ ((1 + Discount_Rate_values).^Lifetime - 1) + term3_A) .* term4_A + electricity_cost_SE);
% Calculate mean and standard deviation of Electricity_Cost_values
LCOH_SOEC_mean = mean(LCOH_SOEC);
LCOH_PEM_mean = mean(LCOH_PEM);
LCOH_AEC_mean = mean(LCOH_AEC);
SOEC_std = 1.9;
PEM_std = 0.77;
AEC_std = 0.72;
% Define the 3-sigma range
lower_limit_S = LCOH_SOEC_mean - 3 * SOEC_std;
upper_limit_S = LCOH_SOEC_mean + 3 * SOEC_std;
lower_limit_P = LCOH_PEM_mean - 3 * PEM_std;
upper_limit_P = LCOH_PEM_mean + 3 * PEM_std;
lower_limit_A = LCOH_AEC_mean - 3 * AEC_std;
upper_limit_A = LCOH_AEC_mean + 3 * AEC_std;
mean_vectors = [LCOH_SOEC_mean; LCOH_PEM_mean; LCOH_AEC_mean];
Lvmv = any(isfinite(mean_vectors),1);
mean_vectors = mean_vectors(:,Lvmv);
limit_vectors = [lower_limit_S; upper_limit_S; lower_limit_P; upper_limit_P; lower_limit_A; upper_limit_A];
Lvlv = any(isfinite(limit_vectors),1);
limit_vectors = limit_vectors(:,Lvlv);
FLHpatch = [FLH(Lvmv) flip(FLH(Lvmv))];
DN = ["SOEC", "PEM", "AEC"];
figure
hold on
cm = eye(3);
for k = 1:size(mean_vectors,1)
patchidx = [1 2] + 2*(k-1);
hp = patch(FLHpatch, [limit_vectors(patchidx(1),:) flip(limit_vectors(patchidx(2),:))], cm(k,:), 'EdgeColor','none', 'FaceAlpha',0.5, 'DisplayName',[DN(k)+" Limits"]);
plot(FLH(Lvmv), mean_vectors(k,:), 'LineWidth',1, 'Color',hp.FaceColor, 'DisplayName',[DN(k)+" Mean"])
end
hold off
xlabel('FLH')
ylabel('LCOH')
legend('Location','best')
figure
hold on
cm = eye(3);
for k = 1:size(mean_vectors,1)
patchidx = [1 2] + 2*(k-1);
hp = patch(FLHpatch, [limit_vectors(patchidx(1),:) flip(limit_vectors(patchidx(2),:))], cm(k,:), 'EdgeColor','none', 'FaceAlpha',0.5, 'DisplayName',[DN(k)+" Limits"]);
plot(FLH(Lvmv), mean_vectors(k,:), 'LineWidth',1, 'Color',hp.FaceColor, 'DisplayName',[DN(k)+" Mean"])
end
hold off
xlabel('FLH')
ylabel('LCOH')
legend('Location','best')
Ax = gca;
Ax.XScale = 'log';
Ax.YScale = 'log';
Make appropriate changes to get the result you want.
.
추가 답변 (1개)
Voss
2024년 1월 3일
Maybe fill along with boundary.
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
Electricity_Cost_mean = 0.255; %EUR/kWh
Electricity_Cost_std = 0.04;
Electricity_Cost_values = normrnd(Electricity_Cost_mean, Electricity_Cost_std, [num_simulations,1]);
Electricity_Cost_values(Electricity_Cost_values < 0.02) = 0.02;
Electricity_Cost_values(Electricity_Cost_values > 0.9) = 0.9;
FLH_min = 1000;
FLH_max = 8760;
FLH = unifrnd(FLH_min, FLH_max, [num_simulations, 1]);
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 + CAPEX_Stack_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;
%PEM parameters
CAPEX_System_PEM_mean = 1450; %$/kW
CAPEX_System_PEM_std = 50;
CAPEX_System_PEM_values = normrnd(CAPEX_System_PEM_mean, CAPEX_System_PEM_std, [num_simulations,1]);
CAPEX_System_PEM_values(CAPEX_System_PEM_values < 1100) = 1100;
CAPEX_System_PEM_values(CAPEX_System_PEM_values > 1800) = 1800;
CAPEX_Stack_PEM_values = 0.35*CAPEX_System_PEM_values; % 35% of CAPEX system
CAPEX_PEM_values = (CAPEX_System_PEM_values + CAPEX_Stack_PEM_values);
OPEX_PEM_values = 3;
System_Efficiency_PEM_mean = 0.58;
System_Efficiency_PEM_std = 0.01;
System_Efficiency_PEM_values = normrnd(System_Efficiency_PEM_mean, System_Efficiency_PEM_std, [num_simulations,1]);
System_Efficiency_PEM_values(System_Efficiency_PEM_values < 0.56) = 0.56;
System_Efficiency_PEM_values(System_Efficiency_PEM_values > 0.6) = 0.6;
%AEC parameters
CAPEX_System_AEC_mean = 950; % $/kW
CAPEX_System_AEC_std = 50;
CAPEX_System_AEC_values = normrnd(CAPEX_System_AEC_mean, CAPEX_System_AEC_std, [num_simulations,1]);
CAPEX_System_AEC_values(CAPEX_System_AEC_values < 500) = 500;
CAPEX_System_AEC_values(CAPEX_System_AEC_values > 1400) = 1400;
CAPEX_Stack_AEC_values = 0.35*CAPEX_System_AEC_values; % 35% of CAPEX system
CAPEX_AEC_values = (CAPEX_System_AEC_values + CAPEX_Stack_AEC_values);
OPEX_AEC_values = 3;
System_Efficiency_AEC_mean = 0.665;
System_Efficiency_AEC_std = 0.05;
System_Efficiency_AEC_values = normrnd(System_Efficiency_AEC_mean, System_Efficiency_AEC_std, [num_simulations,1]);
System_Efficiency_AEC_values(System_Efficiency_AEC_values < 0.63) = 0.63;
System_Efficiency_AEC_values(System_Efficiency_AEC_values > 0.7) = 0.7;
% 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;
LCOH_SOEC = term1_S .* ((term2_S ./ ((1 + Discount_Rate_values).^Lifetime - 1) + term3_S) .* term4_S + Electricity_Cost_values);
% Calculate PEM LCOH values
term1_P = LHV ./ (System_Efficiency_PEM_values);
term2_P = Discount_Rate_values .* (1 + Discount_Rate_values).^Lifetime;
term3_P = (OPEX_PEM_values / 100);
term4_P = CAPEX_PEM_values ./ FLH;
LCOH_PEM = term1_P .* ((term2_P ./ ((1 + Discount_Rate_values).^Lifetime - 1) + term3_P) .* term4_P + Electricity_Cost_values);
% Calculate AEC LCOH values
term1_A = LHV ./ (System_Efficiency_AEC_values);
term2_A = Discount_Rate_values .* (1 + Discount_Rate_values).^Lifetime;
term3_A = (OPEX_AEC_values / 100);
term4_A = CAPEX_AEC_values ./ FLH;
LCOH_AEC = term1_A .* ((term2_A ./ ((1 + Discount_Rate_values).^Lifetime - 1) + term3_A) .* term4_A + Electricity_Cost_values);
% Calculate mean and standard deviation of Electricity_Cost_values
electricity_cost_mean = mean(Electricity_Cost_values);
electricity_cost_std = std(Electricity_Cost_values);
% Define the 3-sigma range
lower_limit = electricity_cost_mean - 3 * electricity_cost_std;
upper_limit = electricity_cost_mean + 3 * electricity_cost_std;
% Filter data based on the 3-sigma range
valid_indices = (Electricity_Cost_values >= lower_limit) & (Electricity_Cost_values <= upper_limit);
FLH_filtered = FLH(valid_indices);
LCOH_SOEC_filtered = LCOH_SOEC(valid_indices);
LCOH_PEM_filtered = LCOH_PEM(valid_indices);
LCOH_AEC_filtered = LCOH_AEC(valid_indices);
% Calculate mean and standard deviation of Electricity_Cost_values
electricity_cost_mean = mean(Electricity_Cost_values);
electricity_cost_std = std(Electricity_Cost_values);
% Define the 3-sigma range
lower_limit = electricity_cost_mean - 3 * electricity_cost_std;
upper_limit = electricity_cost_mean + 3 * electricity_cost_std;
% Filter data based on the 3-sigma range
valid_indices = (Electricity_Cost_values >= lower_limit) & (Electricity_Cost_values <= upper_limit);
FLH_filtered = FLH(valid_indices);
LCOH_SOEC_filtered = LCOH_SOEC(valid_indices);
LCOH_PEM_filtered = LCOH_PEM(valid_indices);
LCOH_AEC_filtered = LCOH_AEC(valid_indices);
% Plot the graph
figure;
hold on
idx = boundary(FLH_filtered, LCOH_SOEC_filtered);
fill(FLH_filtered(idx),LCOH_SOEC_filtered(idx),'g','EdgeColor','none','DisplayName','SOEC','FaceAlpha',0.75)
idx = boundary(FLH_filtered, LCOH_PEM_filtered);
fill(FLH_filtered(idx),LCOH_PEM_filtered(idx),'b','EdgeColor','none','DisplayName','PEM','FaceAlpha',0.75)
idx = boundary(FLH_filtered, LCOH_AEC_filtered);
fill(FLH_filtered(idx),LCOH_AEC_filtered(idx),'y','EdgeColor','none','DisplayName','AEC','FaceAlpha',0.75)
xlabel('FLH');
ylabel('LCOH');
title('3-Sigma Approach Graph');
legend('Location', 'best');
grid on;
hold off;
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Subplots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!