MATLAB Answers

Mysterious "Operands to the || and && operators must be convertible to logical scalar values." error

10 ビュー (過去 30 日間)
Lenilein
Lenilein 2020 年 1 月 21 日
コメント済み: Lenilein 2020 年 1 月 22 日
Hello dear community,
I'm getting following error quite unexpectedly (since I don't have any && or || in my code) while trying to solve an optimization problem with patternsearch:
Operands to the || and && operators must be convertible to logical scalar values.
Error in psAugConverged (line 94)
if ~isempty(infMessage) && strmatch('optimlib:optimfcnchk',infMessage)
Error in pfmincon (line 66)
[X,FVAL,maxConstr,optimState] = psAugConverged(Iterate,X,optimState,psAugParam,options);
Error in patternsearch (line 280)
[X,FVAL,EXITFLAG,OUTPUT] = pfmincon(FUN,X0,optimState,Iterate, ...
Error in Test1 (line 17)
[x,fval,exitflag,output] = patternsearch(fun,x0,A,b,Aeq,beq,lb,ub,@(x)nonlcon(x),options);
Any clue?
My optimization problem is referring to following script called CSolveODE (I made sure to replace all && with & but it didn't fix the issue!) and I am sure that the issue is linked to this script since the optimization code works if I replace the parameter Heatflow.steamair with a parameter from ADatafromExcel or BDatadefinition
% addpath Functions
% run ADatafromExcel
% run BDatadefinition
Position.all=zeros([],1);Characteristics.paper_all=zeros([],2); Characteristics.paper_begsection_all=[];Humidity.air_f_all=zeros([],1);Heatflow.steampaper_all=zeros([],1);Heatflow.steamair_all=zeros([],1);Support.differentialua=zeros([],1);Temperature.air_f_all=zeros([],1);Temperature.air2_f_all=zeros([],1);PAR.CONDITIONS.PAPER_PRE_ALL=[];PAR.CONDITIONS.PAPER_POST_ALL=[];PAR.CONDITIONS.PAPER_COAT_ALL=[];Support.coeffplot_tot=[];
% Solving loop
for k=1:numel(PAR.POSITION_IN_PAPERMACHINE)-1
PAR.TEMP.STEAM_CYL=PAR.TEMP.STEAM_CYL_ALL(k); PAR.AREA.CONV=PAR.AREA.CONV_ALL(k); PAR.AREA.COND=PAR.AREA.COND_ALL(k);PAR.MASSFIBER.P=PAR.MASSFIBER.ALL(k); PAR.ANGLE=PAR.ANGLE_ALL(k);PAR.DIAMETER.CYL=PAR.DIAMETER.CYL_ALL(k); PAR.AREA.CYL_NONCOVERED=PAR.AREA.CYL_NONCOVERED_ALL(k);PAR.MASSFLOW.AIR_PERZONE=PAR.MASSFLOW.AIR_PERZONE_ALL(k);PAR.HEATTRANSF.CYLAIR=PAR.HEATTRANSF.CYLAIR_ALL(k);PAR.MASSTRANSF.PAPERAIR=PAR.MASSTRANSF.PAPERAIR_ALL(k); PAR.HEATTRANSF.PAPERAIR=PAR.HEATTRANSF.PAPERAIR_ALL(k);
PAR.AREA.CONV1=PAR.AREA.CONV_ALL1(k);
% Solving the ODE system
if k<(PAR.CYLNUM.PRE*2+1)
[Position.paper,Characteristics.paper]=ode45(@(L,y) myODE(L,y,PAR.AREA.CONV,PAR.AREA.COND,PAR.HEATTRANSF.PAPERAIR,PAR.MASSTRANSF.PAPERAIR,PAR.MASSFIBER.P,PAR.TEMP.STEAM_CYL,PAR.MOLARWEIGHT.WATER,PAR.SPEED.PAPERMACHINE,PAR.GASCONSTANT,PAR.ANGLE,PAR.HEATTRANSF.CONDENSATES, PAR.DIAMETER.CYL, PAR.THICKNESS.IRONSHELL,PAR.THERMCONDUCTIVITY.IRONSHELL, PAR.HEATTRANSF.CYLSHEET_REF,PAR.DENSITY.DRYPAPER,PAR.DENSITY.WATER,PAR.GRAM.PAPER_DRY,PAR.THERMCONDUCTIVITY.DRYPAPER,PAR.SPECIFICHEAT.FIBER,PAR.SPECIFICHEAT.WATER,PAR.SPECIFICHEAT.VAPOR,PAR.TEMP.AIR_AFTER_STEAMHEATING,PAR.PRESSURE.ATMOSPHERE,PAR.PARTIALPRESSURE.VAPOR_HOOD,densityair(PAR.TEMP.AIR_AFTER_STEAMHEATING),PAR.SPECIFICHEAT.AIR,PAR.PRANDTL.AIR,PAR.SCHMIDT.AIR),PAR.POSITION_IN_PAPERMACHINE(k:k+1),PAR.CONDITIONS.PAPER_PRE); PAR.CONDITIONS.PAPER_PRE=Characteristics.paper(end,:); % Set in B: PAR.CONDITIONS.PAPER_PRE=[PAR.HUM.PAPER_PRE,PAR.TEMP.PAPER_PRE]; and in Y: PAR.HUM.PAPER_PRE=PAR.HUM.PAPER_PRE+x(1)*(PAR.HUM.PAPER_PRE_Mechanicaldryingmeasure-PAR.HUM.PAPER_PRE) & PAR.TEMP.PAPER_PRE=PAR.TEMP.PAPER_PRE+x(2)*(PAR.TEMP.PAPER_PRE_Steamboxmeasure-PAR.HUM.PAPER_PRE);
elseif k>=(PAR.CYLNUM.PRE*2+1) & k<((PAR.CYLNUM.PRE+PAR.CYLNUM.POST)*2+1)
[Position.paper,Characteristics.paper]=ode45(@(L,y) myODE(L,y,PAR.AREA.CONV,PAR.AREA.COND,PAR.HEATTRANSF.PAPERAIR,PAR.MASSTRANSF.PAPERAIR,PAR.MASSFIBER.P,PAR.TEMP.STEAM_CYL,PAR.MOLARWEIGHT.WATER,PAR.SPEED.PAPERMACHINE,PAR.GASCONSTANT,PAR.ANGLE,PAR.HEATTRANSF.CONDENSATES, PAR.DIAMETER.CYL, PAR.THICKNESS.IRONSHELL,PAR.THERMCONDUCTIVITY.IRONSHELL, PAR.HEATTRANSF.CYLSHEET_REF,PAR.DENSITY.DRYPAPER,PAR.DENSITY.WATER,PAR.GRAM.PAPER_DRY,PAR.THERMCONDUCTIVITY.DRYPAPER,PAR.SPECIFICHEAT.FIBER,PAR.SPECIFICHEAT.WATER,PAR.SPECIFICHEAT.VAPOR,PAR.TEMP.AIR_AFTER_STEAMHEATING,PAR.PRESSURE.ATMOSPHERE,PAR.PARTIALPRESSURE.VAPOR_HOOD,densityair(PAR.TEMP.AIR_AFTER_STEAMHEATING),PAR.SPECIFICHEAT.AIR,PAR.PRANDTL.AIR,PAR.SCHMIDT.AIR),PAR.POSITION_IN_PAPERMACHINE(k:k+1),PAR.CONDITIONS.PAPER_POST); PAR.CONDITIONS.PAPER_POST=Characteristics.paper(end,:); % Set in B: PAR.CONDITIONS.PAPER_POST=[PAR.HUM.PAPER_POST,PAR.TEMP.PAPER_POST] and in Y: PAR.HUM.PAPER_POST=PAR.HUM.PAPER_POST+x(2)*(PAR.HUM.PAPER_POST_StarchMeasure-PAR.HUM.PAPER_POST);
else
[Position.paper,Characteristics.paper]=ode45(@(L,y) myODE(L,y,PAR.AREA.CONV,PAR.AREA.COND,PAR.HEATTRANSF.PAPERAIR,PAR.MASSTRANSF.PAPERAIR,PAR.MASSFIBER.P,PAR.TEMP.STEAM_CYL,PAR.MOLARWEIGHT.WATER,PAR.SPEED.PAPERMACHINE,PAR.GASCONSTANT,PAR.ANGLE,PAR.HEATTRANSF.CONDENSATES, PAR.DIAMETER.CYL, PAR.THICKNESS.IRONSHELL,PAR.THERMCONDUCTIVITY.IRONSHELL, PAR.HEATTRANSF.CYLSHEET_REF,PAR.DENSITY.DRYPAPER,PAR.DENSITY.WATER,PAR.GRAM.PAPER_DRY,PAR.THERMCONDUCTIVITY.DRYPAPER,PAR.SPECIFICHEAT.FIBER,PAR.SPECIFICHEAT.WATER,PAR.SPECIFICHEAT.VAPOR,PAR.TEMP.AIR_AFTER_STEAMHEATING,PAR.PRESSURE.ATMOSPHERE,PAR.PARTIALPRESSURE.VAPOR_HOOD,densityair(PAR.TEMP.AIR_AFTER_STEAMHEATING),PAR.SPECIFICHEAT.AIR,PAR.PRANDTL.AIR,PAR.SCHMIDT.AIR),PAR.POSITION_IN_PAPERMACHINE(k:k+1),PAR.CONDITIONS.PAPER_COAT); PAR.CONDITIONS.PAPER_COAT=Characteristics.paper(end,:); % Set in B: PAR.CONDITIONS.PAPER_COAT=[PAR.HUM.PAPER_COAT_CYL,PAR.TEMP.PAPER_COAT]; if PAR.IRDRYER.SWITCH==1; PAR.CONDITIONS.PAPER_COAT(2)=PAR.IRDRYER.TEMP; elseif PAR.IMPDRYER.SWITCH==1; PAR.CONDITIONS.PAPER_COAT(2)=PAR.IMPDRYER.TEMP; end
end
% Plot supporting coefficient
if k<(PAR.CYLNUM.PRE*2+1)
Support.coeffplot=1+Position.paper/(PAR.LENGTH.FREE_ALL(k)+PAR.LENGTH.COND_ALL(k));
elseif k>=(PAR.CYLNUM.PRE*2+1) & k<((PAR.CYLNUM.PRE+PAR.CYLNUM.POST)*2+1)
Support.coeffplot=1+PAR.CYLNUM.PRE+(Position.paper-(sum(PAR.LENGTH.COND_PRE)+sum(PAR.LENGTH.FREE_PRE)))/(PAR.LENGTH.FREE_ALL(k)+PAR.LENGTH.COND_ALL(k));
else
Support.coeffplot=1+PAR.CYLNUM.PRE+PAR.CYLNUM.POST+(Position.paper-(sum(PAR.LENGTH.COND_PRE)+sum(PAR.LENGTH.COND_POST)+sum(PAR.LENGTH.FREE_PRE)+sum(PAR.LENGTH.FREE_POST)))/(PAR.LENGTH.FREE_ALL(k)+PAR.LENGTH.COND_ALL(k));
end
% Value of u and Tp at beginning of a cylinder&no-cylinder section
Characteristics.paper_begsection=Characteristics.paper(end-40,:);
% Differential of u for Balance on air;
if k<(PAR.CYLNUM.PRE*2+1)
Support.differentialu=PAR.CONDITIONS.PAPER_PRE(:,1)-Characteristics.paper_begsection(:,1);
elseif k>=(PAR.CYLNUM.PRE*2+1) & k<((PAR.CYLNUM.PRE+PAR.CYLNUM.POST)*2+1)
Support.differentialu=PAR.CONDITIONS.PAPER_POST(:,1)-Characteristics.paper_begsection(:,1);
else
Support.differentialu=PAR.CONDITIONS.PAPER_COAT(:,1)-Characteristics.paper_begsection(:,1);
end
Humidity.air_f=-Support.differentialu*PAR.GRAM.PAPER_DRY*PAR.SPEED.PAPERMACHINE*PAR.WIDTH.PAPER/PAR.MASSFLOW.AIR_PERZONE+PAR.HUM.AIR_OUTSIDE;
% Heat flow/cylinder to paper & air
if rem(k,2)==0; Heatflow.steamair=0; Heatflow.steampaper=0;
elseif k<PAR.CYLNUM.PRE*2+1 & rem(k,4)==3 & PAR.CONFIG.CYL(k)==1 & PAR.CONFIG.FIRSTCYL(1)==1;Heatflow.steamair=0; Heatflow.steampaper=0;
elseif k<PAR.CYLNUM.PRE*2+1 & rem(k,4)==1 & PAR.CONFIG.CYL(k)==1 & PAR.CONFIG.FIRSTCYL(1)==0; Heatflow.steamair=0; Heatflow.steampaper=0;
elseif k>=(PAR.CYLNUM.PRE*2+1) & k<((PAR.CYLNUM.PRE+PAR.CYLNUM.POST)*2+1) & rem((k-PAR.CYLNUM.PRE*2),4)==3 & PAR.CONFIG.CYL(k)==1 & PAR.CONFIG.FIRSTCYL(2)==1;Heatflow.steamair=0; Heatflow.steampaper=0;
elseif k>=(PAR.CYLNUM.PRE*2+1) & k<((PAR.CYLNUM.PRE+PAR.CYLNUM.POST)*2+1) & rem((k-PAR.CYLNUM.PRE*2),4)==1 & PAR.CONFIG.CYL(k)==1 & PAR.CONFIG.FIRSTCYL(2)==0;Heatflow.steamair=0; Heatflow.steampaper=0;
elseif k>((PAR.CYLNUM.PRE+PAR.CYLNUM.POST)*2+1) & rem((k-(PAR.CYLNUM.PRE+PAR.CYLNUM.POST)*2),4)==3 & PAR.CONFIG.CYL(k)==1 & PAR.CONFIG.FIRSTCYL(3)==1;Heatflow.steamair=0; Heatflow.steampaper=0;
elseif k>((PAR.CYLNUM.PRE+PAR.CYLNUM.POST)*2+1) & rem((k-(PAR.CYLNUM.PRE+PAR.CYLNUM.POST)*2),4)==1 & PAR.CONFIG.CYL(k)==1 & PAR.CONFIG.FIRSTCYL(3)==0;Heatflow.steamair=0; Heatflow.steampaper=0;
elseif k<PAR.CYLNUM.PRE*2+1
Heatflow.steampaper=0.001*heatTransfCoeffSteamtoPaper(Characteristics.paper(1),PAR.ANGLE,PAR.HEATTRANSF.CONDENSATES,PAR.DIAMETER.CYL,PAR.THICKNESS.IRONSHELL,PAR.THERMCONDUCTIVITY.IRONSHELL,PAR.HEATTRANSF.CYLSHEET_REF,PAR.DENSITY.DRYPAPER,PAR.DENSITY.WATER,PAR.GRAM.PAPER_DRY,PAR.THERMCONDUCTIVITY.DRYPAPER,thermalconductivitywater(Characteristics.paper(2)))*(PAR.TEMP.STEAM_CYL-(PAR.CONDITIONS.PAPER_PRE(:,2)+Characteristics.paper_begsection(:,2))/2)*PAR.AREA.CONV; % Heat flow from cylinder to paper in kJ/s (kW)
Heatflow.steamair=0.001*heatTransfCoeffSteamtoAir(PAR.ANGLE,PAR.HEATTRANSF.CONDENSATES,PAR.DIAMETER.CYL,PAR.THICKNESS.IRONSHELL,PAR.THERMCONDUCTIVITY.IRONSHELL,PAR.HEATTRANSF.CYLAIR)*(PAR.TEMP.STEAM_CYL-PAR.TEMP.AIR_AFTER_STEAMHEATING)*(PAR.AREA.CYL_NONCOVERED+pi*(PAR.DIAMETER.CYL/2)^2); % Heat flow from cylinder to air in kJ/s
elseif k>=(PAR.CYLNUM.PRE*2+1) & k<((PAR.CYLNUM.PRE+PAR.CYLNUM.POST)*2+1)
Heatflow.steampaper=0.001*heatTransfCoeffSteamtoPaper(Characteristics.paper(1),PAR.ANGLE,PAR.HEATTRANSF.CONDENSATES,PAR.DIAMETER.CYL,PAR.THICKNESS.IRONSHELL,PAR.THERMCONDUCTIVITY.IRONSHELL,PAR.HEATTRANSF.CYLSHEET_REF,PAR.DENSITY.DRYPAPER,PAR.DENSITY.WATER,PAR.GRAM.PAPER_DRY,PAR.THERMCONDUCTIVITY.DRYPAPER,thermalconductivitywater(Characteristics.paper(2)))*(PAR.TEMP.STEAM_CYL-(PAR.CONDITIONS.PAPER_POST(:,2)+Characteristics.paper_begsection(:,2))/2)*PAR.AREA.CONV; % Heat flow from cylinder to paper in kJ/s
Heatflow.steamair=0.001*heatTransfCoeffSteamtoAir(PAR.ANGLE,PAR.HEATTRANSF.CONDENSATES,PAR.DIAMETER.CYL,PAR.THICKNESS.IRONSHELL,PAR.THERMCONDUCTIVITY.IRONSHELL,PAR.HEATTRANSF.CYLAIR)*(PAR.TEMP.STEAM_CYL-PAR.TEMP.AIR_AFTER_STEAMHEATING)*(PAR.AREA.CYL_NONCOVERED+pi*(PAR.DIAMETER.CYL/2)^2); % Heat flow from cylinder to air in kJ/s
elseif k>((PAR.CYLNUM.PRE+PAR.CYLNUM.POST)*2+1)
Heatflow.steampaper=0.001*heatTransfCoeffSteamtoPaper(Characteristics.paper(1),PAR.ANGLE,PAR.HEATTRANSF.CONDENSATES,PAR.DIAMETER.CYL,PAR.THICKNESS.IRONSHELL,PAR.THERMCONDUCTIVITY.IRONSHELL,PAR.HEATTRANSF.CYLSHEET_REF,PAR.DENSITY.DRYPAPER,PAR.DENSITY.WATER,PAR.GRAM.PAPER_DRY,PAR.THERMCONDUCTIVITY.DRYPAPER,thermalconductivitywater(Characteristics.paper(2)))*(PAR.TEMP.STEAM_CYL-(PAR.CONDITIONS.PAPER_COAT(:,2)+Characteristics.paper_begsection(:,2))/2)*PAR.AREA.CONV; % Heat flow from cylinder to paper in kJ/s
Heatflow.steamair=0.001*heatTransfCoeffSteamtoAir(PAR.ANGLE,PAR.HEATTRANSF.CONDENSATES,PAR.DIAMETER.CYL,PAR.THICKNESS.IRONSHELL,PAR.THERMCONDUCTIVITY.IRONSHELL,PAR.HEATTRANSF.CYLAIR)*(PAR.TEMP.STEAM_CYL-PAR.TEMP.AIR_AFTER_STEAMHEATING)*(PAR.AREA.CYL_NONCOVERED+pi*(PAR.DIAMETER.CYL/2)^2); % Heat flow from cylinder to air in kJ/s
end
if rem(k,2)~=0 & PAR.PRESSURE.STEAM_CYL_ALL(k)==0; Heatflow.steamair=0; Heatflow.steampaper=0;end
Support.Phi= 1-exp(-(47.58*Characteristics.paper(1)^1.877+0.10085*(Characteristics.paper(2))*Characteristics.paper(1)^1.0585));
Support.DHevap = (PAR.GASCONSTANT/PAR.MOLARWEIGHT.WATER)*0.10085*(Characteristics.paper(1)^1.0585)*((Characteristics.paper(2)+273.15)^2)*(1-Support.Phi)/Support.Phi+2501-2.3237*Characteristics.paper(2); % in kJ/kg water
Temperature.air_f=(PAR.MASSFLOW.AIR_PERZONE*Entha(PAR.TEMP.AIR_AFTER_STEAMHEATING,PAR.HUM.AIR_OUTSIDE,PAR.SPECIFICHEAT.AIR,PAR.SPECIFICHEAT.VAPOR,Latentheatvaporization(PAR.TEMP.AIR_AFTER_STEAMHEATING))-Support.DHevap*Support.differentialu*PAR.GRAM.PAPER_DRY*PAR.SPEED.PAPERMACHINE*PAR.WIDTH.PAPER+Heatflow.steamair-PAR.MASSFLOW.AIR_PERZONE*Latentheatvaporization(PAR.TEMP.AIR_AFTER_STEAMHEATING)*Humidity.air_f)/(PAR.MASSFLOW.AIR_PERZONE*(PAR.SPECIFICHEAT.AIR+PAR.SPECIFICHEAT.VAPOR*Humidity.air_f));
if Temperature.air_f<0;Temperature.air_f=0;end
%%% Formula taken from a paper
Temperature.air2_f=0.5*PAR.TEMP.AIR_AFTER_STEAMHEATING+(1-0.5)*Characteristics.paper_begsection(2);
Position.all=[Position.all;Position.paper];Characteristics.paper_all=[Characteristics.paper_all;Characteristics.paper];PAR.CONDITIONS.PAPER_PRE_ALL=[PAR.CONDITIONS.PAPER_PRE_ALL;PAR.CONDITIONS.PAPER_PRE];PAR.CONDITIONS.PAPER_POST_ALL=[PAR.CONDITIONS.PAPER_POST_ALL;PAR.CONDITIONS.PAPER_POST];PAR.CONDITIONS.PAPER_COAT_ALL=[PAR.CONDITIONS.PAPER_COAT_ALL;PAR.CONDITIONS.PAPER_COAT];Characteristics.paper_begsection_all=[Characteristics.paper_begsection_all;Characteristics.paper_begsection];Heatflow.steampaper_all=[Heatflow.steampaper_all;Heatflow.steampaper];Heatflow.steamair_all=[Heatflow.steamair_all;Heatflow.steamair];Humidity.air_f_all=[Humidity.air_f_all;Humidity.air_f];Support.differentialua=[Support.differentialua;Support.differentialu];Temperature.air_f_all=[Temperature.air_f_all;Temperature.air_f];Temperature.air2_f_all=[Temperature.air2_f_all;Temperature.air2_f];Support.coeffplot_tot=[Support.coeffplot_tot;Support.coeffplot];
end
% keeping only every second value of:
PAR.ENTH.STEAM_CYL_ALL(2:2:end)=[];PAR.ENTH.COND_CYL_ALL(2:2:end)=[];Heatflow.steamair_all(2:2:end)=[];Heatflow.steampaper_all(2:2:end)=[];
Massflow.steam_cyl_all=3.6*(Heatflow.steamair_all+Heatflow.steampaper_all)./((PAR.ENTH.STEAM_CYL_ALL'-PAR.ENTH.COND_CYL_ALL').*(1-PAR.BLOWTHROUGH_COEFF_CYL));
if PAR.STEAMGROUPS.EMPTYCYLNUM~=0
for i=1:numel(PAR.STEAMGROUPS.EMPTYCYLNUM)
k=PAR.STEAMGROUPS.EMPTYCYLNUM(i);
Massflow.steam_cyl_all(k)=0;
end
end
Massflow.steam_cyltot=sum(Massflow.steam_cyl_all); % total steam consumption for cylinders in t steam/h
Heatflow.steampapertot=sum(Heatflow.steampaper_all);
Heatflow.steamairtot=sum(Heatflow.steamair_all);
DemandSteamSpec.cyl_all=Massflow.steam_cyl_all/PAR.PRODRATE.PAPER; % specific steam consumption/cylinder in kg steam/kg paper
DemandSteamSpec.cyltot=sum(DemandSteamSpec.cyl_all); % total cylinder specific steam consumption in kg steam/kg paper
EnergyFlowSpec.steam_cyl_all_kJ=DemandSteamSpec.cyl_all.*PAR.ENTH.STEAM_CYL_ALL; % specific Energy consumption/cylinder in kJ/kg paper
EnergyFlowSpec.steam_cyltot_kJ=sum(EnergyFlowSpec.steam_cyl_all_kJ); % total cylinder specific Energy consumption in kJ/kg paper
And this is the optimization problem:
clearvars; clear; addpath Functions;
fun=@(x)Investcosts(x);
x0 = [1 1]; % Start point (row vector)
A=[]; % Equality constraint
b=[]; % Equality constraint
Aeq=[]; % Inequality constraint
beq=[]; % Equality constraint
lb=[0 0]; % lower bound for x
ub=[1 1]; % upper bound for x
options = optimoptions('patternsearch','ScaleMesh','off','TolMesh',0.9);
[x,fval,exitflag,output] = patternsearch(fun,x0,A,b,Aeq,beq,lb,ub,@(x)nonlcon(x),options);
function f=Investcosts(x)
A = 2;
B = 3;
f = A*x(1)+B*x(2);
end
function [CO2Emissionsyear,ceq]=nonlcon(x)
run ADatafromExcel; run BDatadefinition;
PAR.HUM.PAPER_PRE_Mechanicaldryingmeasure=PAR.HUM.PAPER_PRE_A;
PAR.HUM.PAPER_PRE=PAR.HUM.PAPER_PRE+x(1)*(PAR.HUM.PAPER_PRE_Mechanicaldryingmeasure-PAR.HUM.PAPER_PRE);
PAR.TEMP.PAPER_PRE_Steamboxmeasure=PAR.TEMP.PAPER_PRE_A ;
PAR.TEMP.PAPER_PRE=PAR.TEMP.PAPER_PRE+x(2)*(PAR.TEMP.PAPER_PRE_Steamboxmeasure-PAR.HUM.PAPER_PRE);
run CSolveODE;
CO2Emissionsyear=Heatflow.steamairtot*24*365/1000-110;
ceq=[];
end

  1 件のコメント

Allen
Allen 2020 年 1 月 21 日
Though you are not using && or ||, you do have a & in a few of your if statements. The difference between the two is that for A & B, both A and B are evaluated, while for A && B, B is only evaluated when A is true. When using if-statements to evaluate multiple conditions, you need to be certain that each conditional statement is return a scalar and not a vector or array. For example:
a = [1 2 3 4 5];
b = 10;
if a>2 && b==10
% a>5 returns a logical array >> [0 0 1 1 1]
% This can create the error that you are seeing and you might want to consider
% changing to something more along the following:
% any(a>5) OR all(a>5)
end

サインイン to comment.

回答 (2 件)

Fangjun Jiang
Fangjun Jiang 2020 年 1 月 21 日
this line
if ~isempty(infMessage) && strmatch('optimlib:optimfcnchk',infMessage)

  0 件のコメント

サインイン to comment.


Steven Lord
Steven Lord 2020 年 1 月 21 日
Can you check to confirm that you haven't written your own functions named isempty, strmatch, or not that are shadowing the functions by those names included in MATLAB? Check this using the which function.
which -all isempty
which -all strmatch
which -all not
For each of these, you can most likely ignore any lines in the output that end with "% <some class name> method". You can also ignore the strmatch.m file in the toolbox\matlab\strfun subdirectory under matlabroot. If you see any others, can you list them?

  2 件のコメント

Fangjun Jiang
Fangjun Jiang 2020 年 1 月 21 日
when strmatch() returns empty [], the error message will appear
~isempty('abc') && strmatch('abc',{'a','b','c'})
Or, strmatch could return a vector
>> strmatch('a',char('a','a','a'))
ans =
1
2
3
Lenilein
Lenilein 2020 年 1 月 22 日
Hi Steven,
Thank you for your answer! I don't get any more results than the ones you describe, see the command results below. Anything else I could try?
>> which -all isempty
built-in (C:\Program Files\MATLAB\R2019b\toolbox\matlab\elmat\isempty)
built-in (C:\Program Files\MATLAB\R2019b\toolbox\matlab\elmat\@double\isempty) % double method
built-in (C:\Program Files\MATLAB\R2019b\toolbox\matlab\elmat\@int16\isempty) % int16 method
built-in (C:\Program Files\MATLAB\R2019b\toolbox\matlab\elmat\@int32\isempty) % int32 method
built-in (C:\Program Files\MATLAB\R2019b\toolbox\matlab\elmat\@int64\isempty) % int64 method
built-in (C:\Program Files\MATLAB\R2019b\toolbox\matlab\elmat\@int8\isempty) % int8 method
built-in (C:\Program Files\MATLAB\R2019b\toolbox\matlab\elmat\@logical\isempty) % logical method
built-in (C:\Program Files\MATLAB\R2019b\toolbox\matlab\elmat\@single\isempty) % single method
built-in (C:\Program Files\MATLAB\R2019b\toolbox\matlab\elmat\@uint16\isempty) % uint16 method
built-in (C:\Program Files\MATLAB\R2019b\toolbox\matlab\elmat\@uint32\isempty) % uint32 method
built-in (C:\Program Files\MATLAB\R2019b\toolbox\matlab\elmat\@uint64\isempty) % uint64 method
built-in (C:\Program Files\MATLAB\R2019b\toolbox\matlab\elmat\@uint8\isempty) % uint8 method
isempty is a built-in method % string method
C:\Program Files\MATLAB\R2019b\toolbox\matlab\codetools\@mtree\isempty.m % mtree method
isempty is a built-in method % containers.Map method
isempty is a built-in method % connector.internal.LoggerLevel method
C:\Program Files\MATLAB\R2019b\toolbox\matlab\datatypes\@tabular\isempty.m % tabular method
C:\Program Files\MATLAB\R2019b\toolbox\matlab\datatypes\categorical\@categorical\isempty.m % categorical method
C:\Program Files\MATLAB\R2019b\toolbox\matlab\bigdata\@tall\isempty.m % tall method
C:\Program Files\MATLAB\R2019b\toolbox\shared\statslib\@dataset\isempty.m % dataset method
C:\Program Files\MATLAB\R2019b\toolbox\matlab\timeseries\@tscollection\isempty.m % tscollection method
>> which -all strmatch
C:\Program Files\MATLAB\R2019b\toolbox\matlab\strfun\strmatch.m
C:\Program Files\MATLAB\R2019b\toolbox\matlab\strfun\@opaque\strmatch.m % opaque method
>> which -all not
built-in (C:\Program Files\MATLAB\R2019b\toolbox\matlab\ops\@char\not) % char method
built-in (C:\Program Files\MATLAB\R2019b\toolbox\matlab\ops\@double\not) % double method
built-in (C:\Program Files\MATLAB\R2019b\toolbox\matlab\ops\@int16\not) % int16 method
built-in (C:\Program Files\MATLAB\R2019b\toolbox\matlab\ops\@int32\not) % int32 method
built-in (C:\Program Files\MATLAB\R2019b\toolbox\matlab\ops\@int64\not) % int64 method
built-in (C:\Program Files\MATLAB\R2019b\toolbox\matlab\ops\@int8\not) % int8 method
built-in (C:\Program Files\MATLAB\R2019b\toolbox\matlab\ops\@logical\not) % logical method
built-in (C:\Program Files\MATLAB\R2019b\toolbox\matlab\ops\@single\not) % single method
built-in (C:\Program Files\MATLAB\R2019b\toolbox\matlab\ops\@uint16\not) % uint16 method
built-in (C:\Program Files\MATLAB\R2019b\toolbox\matlab\ops\@uint32\not) % uint32 method
built-in (C:\Program Files\MATLAB\R2019b\toolbox\matlab\ops\@uint64\not) % uint64 method
built-in (C:\Program Files\MATLAB\R2019b\toolbox\matlab\ops\@uint8\not) % uint8 method
C:\Program Files\MATLAB\R2019b\toolbox\matlab\codetools\@mtree\not.m % mtree method
not is a built-in method % connector.internal.LoggerLevel method

サインイン to comment.

サインイン してこの質問に回答します。


Translated by