MATLAB Answers

Error: Complex values ​​are not supported

57 views (last 30 days)
Eduardo Braga
Eduardo Braga on 11 Mar 2021
Commented: Alan Weiss on 12 Mar 2021
Hi. I'm trying to perform a multiobjective optimization together with aspen plus. I'm using the optimization toolbox (gamultiobj). But after hours, I found the following error: "Complex values ​​are not supported". How should I proceed?
function [TAC] = Objective(x)
global Aspen
Aspen = actxserver('Apwn.Document.36.0');
[~,mess]=fileattrib;
Aspen.invoke('InitFromArchive2',[mess.Name '\SimulationACRYL2.bkp']);
Aspen.Visible = 1;
Aspen.SuppressDialogs = 1;
Aspen.Engine.Run2(1);
while Aspen.Engine.IsRunning == 1
pause(0.5);
end
Stages = round(x(1) + 2);
Pressure = x(2);
Feed_Stage = round((Stages-2)*x(3) + 1);
Aspen.Tree.FindNode("\Data\Blocks\B2\Input\NSTAGE").Value = Stages;
Aspen.Tree.FindNode("\Data\Blocks\B2\Subobjects\Column Internals\INT-1\Input\CA_STAGE2\INT-1\CS-1").Value = Stages - 1;
Aspen.Tree.FindNode("\Data\Blocks\B2\Input\PRES1").Value = Pressure;
Aspen.Tree.FindNode("\Data\Blocks\B2\Input\FEED_STAGE\S50").Value = Feed_Stage;
Aspen.Reinit; % Reinit simulation
Aspen.Engine.Run2(1); %Run the simulation. (1) ---> Matlab isnt busy; (0) Matlab is Busy;
time = 1;
Error = 0;
while Aspen.Engine.IsRunning == 1 % 1 --> If Aspen is running; 0 ---> If Aspen stop.
pause(0.5);
time = time+1;
if time==40 % Control of simulation time.
Aspen.Engine.Stop;
Error = 1;
end
end
Conv = Aspen.Tree.FindNode("\Data\Results Summary\Run-Status\Output\PER_ERROR").Value;
if Error == 0 && Conv == 1
% column cost
Lang_F = 4.74;
Diameter = Aspen.Tree.FindNode("\Data\Blocks\B2\Subobjects\Column Internals\INT-1\Input\CA_DIAM\INT-1\CS-1").Value;
Number_trays = double(Aspen.Tree.FindNode("\Data\Blocks\B2\Input\NSTAGE").Value - 2);
height_Column = 0.5*(Number_trays)+2;
heat_reboiler = (Aspen.Tree.FindNode("\Data\Blocks\B2\Output\REB_DUTY").Value)*4.1868;
Presure_project = 441.3;
Tension = 108000;
Column_thickness = ((Presure_project*Diameter)/((2*Tension*0.85)-(1.2*Presure_project))) + 0.003;
Density_carbon_steel = 7861.1;
Column_side_volume = 3.14*Column_thickness*height_Column*Diameter;
Column_side_mass = (Column_side_volume*Density_carbon_steel)*2.205;
External_radius = (Diameter + 2*Column_thickness)/2;
Cover_volume = 4*3.14*(External_radius^2)*Column_thickness*2;
Cover_mass = (Cover_volume*Density_carbon_steel)*2.205;
total_mass = Column_side_mass + Cover_mass;
Cv = exp((7.2756 + 0.18255*(log(total_mass))) + (0.02297*((log(total_mass))^2)));
Diameterft = Diameter*3.281;
height_Columnft = height_Column*3.281;
Cpl = 300.9*((Diameterft)^0.63316)*(height_Columnft^0.80161);
Factor_material_column = 1;
FNT = 1;
FTT = 1;
FTM = 1;
CBT = 468*exp(0.1739*Diameterft);
CT = CBT*FTM*FTT*FNT*Number_trays;
CP = Factor_material_column*Cv + Cpl;
Cost_column = CP + CT;
% condenser cost
Temp_out_fluid_cold = 20;
Temp_in_fluid_cold = 5;
Temp_in_fluid_hot = Aspen.Tree.FindNode("\Data\Streams\S4\Output\TEMP_OUT\MIXED").Value;
Temp_out_fluid_hot = Aspen.Tree.FindNode("\Data\Streams\S4\Output\TEMP_OUT\MIXED").Value;
Temperature_exchange_termic = ((Temp_in_fluid_hot - Temp_out_fluid_cold) - (Temp_out_fluid_hot - Temp_in_fluid_cold))/log((Temp_in_fluid_hot - Temp_out_fluid_cold)/(Temp_out_fluid_hot - Temp_in_fluid_cold));
Factor_exchange_termic = 0.85;
coefficient_exchange_termic = 850;
Heat_condenser = (Aspen.Tree.FindNode("\Data\Blocks\B2\Output\COND_DUTY").Value)*4.1868;
Area_condenser = ((Heat_condenser)/(Temperature_exchange_termic*coefficient_exchange_termic*Factor_exchange_termic))*10.76;
Cost_condenser = exp(11.0545 - 0.9228*(log(Area_condenser)) + 0.09861*(log(Area_condenser)^2));
Pipe_length = 1;
Type_Material_Condenser = 1;
pressure_condenser = 1;
Condenser_total_cost = Cost_condenser*Pipe_length*Type_Material_Condenser*pressure_condenser;
%Reboiler cost
Temp_in_fluid_hot_reboiler = 127.5;
Temp_out_fluid_hot_reboiler = 127.5;
Temp_out_fluid_cold_reboiler = Aspen.Tree.FindNode("\Data\Streams\12\Output\TEMP_OUT\MIXED").Value;
Temp_in_fluid_cold_reboiler = Aspen.Tree.FindNode("\Data\Streams\12\Output\TEMP_OUT\MIXED").Value;
Temperature_exchange_termic_reboiler = ((Temp_in_fluid_hot_reboiler - Temp_out_fluid_cold_reboiler) - (Temp_out_fluid_hot_reboiler - Temp_in_fluid_cold_reboiler))/log((Temp_in_fluid_hot_reboiler - Temp_out_fluid_cold_reboiler)/(Temp_out_fluid_hot_reboiler - Temp_in_fluid_cold_reboiler));
Factor_exchange_termic_reboiler = 0.85;
coefficient_exchange_termic_reboiler = 1560;
Area_reboiler = ((heat_reboiler)/(Temperature_exchange_termic_reboiler*coefficient_exchange_termic_reboiler*Factor_exchange_termic_reboiler))*10.76;
Cost_reboiler = exp(11.967 - 0.8709*(log(Area_reboiler)) + 0.09005*(log(Area_reboiler)^2));
Pipe_length_reboiler = 1;
Type_Material_reboiler = 1;
pressure_reboiler = 1;
Reboiler_total_cost = Cost_reboiler*Pipe_length_reboiler*Type_Material_reboiler*pressure_reboiler;
% cost of utilities
Chilled_water_cost = ((Aspen.Tree.FindNode("\Data\Blocks\B2\Output\COND_DUTY").Value)*4.1868)*31536000*0.0000000009258;
Steam_Cost = ((Aspen.Tree.FindNode("\Data\Blocks\B2\Output\REB_DUTY").Value)*4.1868)*0.000000004607*31536000;
TAC(1) = (Cost_column + Condenser_total_cost + Reboiler_total_cost)*Lang_F*1.14*1.1906/10;
TAC(2) = Steam_Cost + Chilled_water_cost;
else
TAC(1) = inf;
TAC(2) = inf;
end
Aspen.Quit();
end

Accepted Answer

Alan Weiss
Alan Weiss on 12 Mar 2021
I don't know where your objective function creates complex values, though I suspect that one or more of your logarithm calls has a negative number as an argument. You can fix this problem by making your code more robust. Test all inputs to logarithms (or square roots or similar) to ensure that they are not negative before applying the functions. Or, if you can, impose bounds or linear inequality constraints to ensure that negative arguments do not get passed. Unfortunately, gamultiobj does not satisfy nonlinear inequality constraints at intermediate iterations, so you cannot fix the problem by imposing nonlinear constraints.
Alan Weiss
MATLAB mathematical toolbox documentation
  2 Comments
Alan Weiss
Alan Weiss on 12 Mar 2021
Sorry, I don't know where that error arises. Is that from Aspen? If so, it is not a MATLAB issue, and I don't know anything about it.
Alan Weiss
MATLAB mathematical toolbox documentation

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!