How to solve this error?

1 visualizzazione (ultimi 30 giorni)
Minhee
Minhee il 25 Nov 2023
Modificato: Voss il 25 Nov 2023
num_samples = 10000;
CAPEX_System_mean = 4200;
CAPEX_System_std = 500;
CAPEX_System_values = normrnd(CAPEX_System_mean, CAPEX_System_std, [num_simulations,1]);
CAPEX_System_values(CAPEX_System_values < 2800) = 2800;
CAPEX_System_values(CAPEX_System_values > 5600) = 5600;
CAPEX_Stack_values = 0.05*CAPEX_System_values;
System_size_values = [1000, 10000, 50000, 100000];
CAPEX_values = (CAPEX_System_values+CAPEX_Stack_values)*System_size_values;
OPEX_values = 0.03*CAPEX_values;
System_Efficiency_mean = 0.775;
System_Efficiency_std = 0.05;
System_Efficiency_values = normrnd(System_Efficiency_mean, System_Efficiency_std, [num_simulations,1]);
System_Efficiency_values(System_Efficiency_values < 0.74) = 0.74;
System_Efficiency_values(System_Efficiency_values > 0.81) = 0.81;
LHV = 33.33;
Discount_Rate_min = 0.06;
Discount_Rate_max = 0.08;
Discount_Rate_values = unifrnd(Discount_Rate_min, Discount_Rate_max, [num_simulations, 1]);
Lifetime = 20;
Electricity_Cost_mean = 70;
Electricity_Cost_std = 105;
Electricity_Cost_values = normrnd(Electricity_Cost_mean, Electricity_Cost_std, [num_simulations,1]);
Electricity_Cost_values(Electricity_Cost_values < 70) = 70;
Electricity_Cost_values(Electricity_Cost_values > 105) = 105;
Full_Load_Hour_min = 0;
Full_Load_Hour_max = 8760;
Full_Load_Hour_values = unifrnd(Full_Load_Hour_min, Full_Load_Hour_max, [num_simulations, 1]);
term1 = LHV ./ (System_Efficiency_values .* 100);
term2 = Discount_Rate_values .* (1 + Discount_Rate_values).^Lifetime;
term3 = (OPEX_values / 100);
term4 = CAPEX_values ./ Full_Load_Hour_values;
LCOH = term1 .* (term2 / ((1 + Discount_Rate_values).^Lifetime - 1) + term3) .* term4 + Electricity_Cost_values;
figure;
scatter(System_size_values, LCOH, 20, 'filled', 'MarkerEdgeColor', 'b', 'MarkerFaceColor', 'b');
xlabel('System_size_values');
ylabel('LCOH');
title('Monte Carlo Simulation');
Arrays have incompatible sizes for this operation.
Error in Ex1 (line 46)
LCOH = term1 .* (term2 / ((1 + Discount_Rate_values).^Lifetime - 1) + term3) .* term4 + Electricity_Cost_values;
How can I solve this error?

Risposte (1)

Voss
Voss il 25 Nov 2023
Modificato: Voss il 25 Nov 2023
Use ./ instead of /
% num_samples = 10000;
num_simulations = 1000; % fixed variable name and decreased value for testing
CAPEX_System_mean = 4200;
CAPEX_System_std = 500;
CAPEX_System_values = normrnd(CAPEX_System_mean, CAPEX_System_std, [num_simulations,1]);
CAPEX_System_values(CAPEX_System_values < 2800) = 2800;
CAPEX_System_values(CAPEX_System_values > 5600) = 5600;
CAPEX_Stack_values = 0.05*CAPEX_System_values;
System_size_values = [1000, 10000, 50000, 100000];
CAPEX_values = (CAPEX_System_values+CAPEX_Stack_values)*System_size_values;
OPEX_values = 0.03*CAPEX_values;
System_Efficiency_mean = 0.775;
System_Efficiency_std = 0.05;
System_Efficiency_values = normrnd(System_Efficiency_mean, System_Efficiency_std, [num_simulations,1]);
System_Efficiency_values(System_Efficiency_values < 0.74) = 0.74;
System_Efficiency_values(System_Efficiency_values > 0.81) = 0.81;
LHV = 33.33;
Discount_Rate_min = 0.06;
Discount_Rate_max = 0.08;
Discount_Rate_values = unifrnd(Discount_Rate_min, Discount_Rate_max, [num_simulations, 1]);
Lifetime = 20;
Electricity_Cost_mean = 70;
Electricity_Cost_std = 105;
Electricity_Cost_values = normrnd(Electricity_Cost_mean, Electricity_Cost_std, [num_simulations,1]);
Electricity_Cost_values(Electricity_Cost_values < 70) = 70;
Electricity_Cost_values(Electricity_Cost_values > 105) = 105;
Full_Load_Hour_min = 0;
Full_Load_Hour_max = 8760;
Full_Load_Hour_values = unifrnd(Full_Load_Hour_min, Full_Load_Hour_max, [num_simulations, 1]);
term1 = LHV ./ (System_Efficiency_values .* 100);
term2 = Discount_Rate_values .* (1 + Discount_Rate_values).^Lifetime;
term3 = (OPEX_values / 100);
term4 = CAPEX_values ./ Full_Load_Hour_values;
% LCOH = term1 .* (term2 / ((1 + Discount_Rate_values).^Lifetime - 1) + term3) .* term4 + Electricity_Cost_values;
LCOH = term1 .* (term2 ./ ((1 + Discount_Rate_values).^Lifetime - 1) + term3) .* term4 + Electricity_Cost_values;
figure;
scatter(System_size_values, LCOH, 20, 'filled', 'MarkerEdgeColor', 'b', 'MarkerFaceColor', 'b');
xlabel('System_size_values');
ylabel('LCOH');
title('Monte Carlo Simulation');

Tag

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by