unable to get code to run please help
Show older comments
% Define the objective function to maximize economic impact
function economic_impact = PowerPlantCode2(P)
function fmincon
% Define the optimization problem
options = optimset('fmincon');
options.Display = 'iter';
options.MaxFunEvals = 10;
% Given
electricity_price = 0.47; % $/kWh
water_price = 2; % $/cubic meter
T_warm = 27; % Warm surface water temperature (°C)
T_cold = 4; % Cold deep-ocean water temperature (°C)
dT_condenser = 3; % Terminal temperature difference in the
condenser (C);
% Other probable variables
T_condenser = 12; % degrees Celcius
Run_Time = 1000; % hours
mdot_FC_Discharge = 20; % kg/s
rho_water = 997; % kg/m3
cp = 4.186; % kJ/kg
% Water mass flow rates
mdot_warm = 70; % in kg/s
mdot_cold = 25; % in kg/s
% Electricity generation and desalinated water production
Ideal_power = mdot_warm*cp*(T_warm-T_condenser); % kW
MaxPosOutput = Ideal_power*1-(T_condenser+273)/(T_warm+273); % kW
electricity_usage = Ideal_power*Run_Time/1000; % in kWh
water_volume = (mdot_warm - mdot_FC_Discharge)/rho_water; % in cubic
meters
% Economic impact
electricity_revenue = electricity_usage*electricity_price; % in dollars
water_revenue = water_volume*water_price; % in dollars
economic_impact = electricity_revenue + water_revenue;
% Initial guess and bounds for flash chamber pressure (P)
P0 = 1000; % Initial guess in kPa
lb = 500; % Lower bound in kPa
ub = 10000; % Upper bound in kPa
% Ooptimization
P_optimal, max_economic_impact = fminconPowerPlantCode2; P0; (); (),
(); (); lb; ub; (0);
% Display
fprintf('Optimal Flash Chamber Pressure: %f bar\n', P_optimal);
fprintf('Maximum Economic Impact: $%f\n', max_economic_impact);
Accepted Answer
More Answers (1)
Torsten
on 8 Oct 2023
This should be the rough structure of the optimization code. But you don't use your optimization variable P in the objective function. Thus you always compute the same value for "economic_impact".
% Initial guess and bounds for flash chamber pressure (P)
P0 = 1000; % Initial guess in kPa
lb = 500; % Lower bound in kPa
ub = 10000; % Upper bound in kPa
% Ooptimization
% Define the optimization problem
%options = optimset('fmincon');
options.Display = 'iter';
options.MaxFunEvals = 10;
[P_optimal, max_economic_impact] = fmincon(@PowerPlantCode2, P0, [],[],[],[],lb,ub,[],options)
% Display
fprintf('Optimal Flash Chamber Pressure: %f bar\n', P_optimal);
fprintf('Maximum Economic Impact: $%f\n', max_economic_impact);
% Define the objective function to maximize economic impact
function economic_impact = PowerPlantCode2(P)
% Given
electricity_price = 0.47; % $/kWh
water_price = 2; % $/cubic meter
T_warm = 27; % Warm surface water temperature (°C)
T_cold = 4; % Cold deep-ocean water temperature (°C)
dT_condenser = 3; % Terminal temperature difference in the
% Other probable variables
T_condenser = 12; % degrees Celcius
Run_Time = 1000; % hours
mdot_FC_Discharge = 20; % kg/s
rho_water = 997; % kg/m3
cp = 4.186; % kJ/kg
% Water mass flow rates
mdot_warm = 70; % in kg/s
mdot_cold = 25; % in kg/s
% Electricity generation and desalinated water production
Ideal_power = mdot_warm*cp*(T_warm-T_condenser); % kW
MaxPosOutput = Ideal_power*1-(T_condenser+273)/(T_warm+273); % kW
electricity_usage = Ideal_power*Run_Time/1000; % in kWh
water_volume = (mdot_warm - mdot_FC_Discharge)/rho_water; % in cubic meters
% Economic impact
electricity_revenue = electricity_usage*electricity_price; % in dollars
water_revenue = water_volume*water_price; % in dollars
economic_impact = electricity_revenue + water_revenue;
economic_impact = -economic_impact; % minus because you want to maximize, not minimize
end
Categories
Find more on Vector Fields in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!