Matrix Optimization, optimizing a 336 by 2 matrix, x
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hello,
I'm working on , with certain constraints as specified in the code. Unfortunately I'm encountering a bunch of warnings that i'm just not able to get rid of despite multiple code edits, mentioned below. Any advise would be help full.
CODE
%global variables
global Tch Pch Mch Ad C1Tin Ocd mw1 mw2 mtw SpP ncd OEn NEn C1w C2w Tow EnvAirP PolyCompEff IsenExpo PolyCompExpo CompRatio MaxCP Cp_air HxEff WaterIn WaterOut Cp_water IFChP IChT R PolyTurbEff PolyTurbExpo Pexp Vch C1P C2P C1Tout C2Tin C2Tout HXout;
EnvAirP = 101;
PolyCompEff = 0.85;
IsenExpo = 1.4;
PolyCompExpo = 1.503;
CompRatio = 8;
MaxCP = 18.6;
Cp_air = 1;
HxEff = 0.8;
WaterIn = 293.15;
WaterOut = 368.15;
Cp_water = 4.184;
IFChP = 2000;
IChT = 400;
R = 0.287;
PolyTurbEff = 0.8;
PolyTurbExpo = 1.297;
Pexp = 700;
Vch = 10;
Pch = 0;
%Matrix input variables
%C1Tin - Compressor 1 Inlet air temp
%Amd - Company air mass flow Demand
%Ocd - Overall Old Company Power Demand
%Ad - Air Density
x0 = [0,0];
lb = [0,0];
ub = [];
x = patternsearch(@fun,x0,[],[],[],[],lb,ub,@nlinconst);
C1P = EnvAirP*CompRatio;
C2P = C1P*CompRatio;
C1Tout(:,1) = C1Tin(:,1)*(CompRatio^(PolyCompExpo/(PolyCompExpo - 1)));
C2Tin(:,1) = WaterIn + HxEff*(WaterIn - C1Tout(:,1));
C2Tout(:,1) = C2Tin(:,1)*CompRatio^(PolyCompExpo/(PolyCompExpo - 1));
HXout(:,1) = WaterIn + HxEff*(WaterIn - C2Tout(:,1));
mw1(:,1) = x(:,1).*Cp_air.*(C1Tout(:,1) - C2Tin(:,1))./(Cp_air*(WaterOut - WaterIn));
mw2(:,1) = x(:,1).*Cp_air.*(C2Tout(:,1) - HXout(:,1))./(Cp_air*(WaterOut - WaterIn));
mtw(:,1) = mw1(:,1) + mw2(:,1);
SpP(:,1) = (PolyCompEff^(-1))*Cp_air.*C1Tin(:,1).*(CompRatio^(PolyCompExpo/(PolyCompExpo - 1)));
ncd(:,1) = C1w(:,1) + C2w(:,1) - Tow(:,1) + Ocd(:,1) - SpP(:,1).*x(:,2)./Ad(:,1).*2118.9;
OEn = sum(Ocd(:,1),'all')*0.5;
NEn = sum(ncd(:,1),'all')*0.5;
for i = 1:336
Tch(i+1,3) = Tch(i,3) + (Mch(i,1)^-1).*(1-IsenExpo^-1).*(x(i,1).*HXout(i,1) - x(i,2).*Tch(i+1,1)).*1800;
end
function [c,ceq] = nlinconst(x)
c(:,1) = OEn - NEn;
c(:,2) = 700 - Pch(:,1);
c(:,3) = x(:,1) - 0.2;
c(:,4) = x(:,2) - 0.2;
c(:,5) = Pch(:,1) - 6464;
c(:,6) = C1w(:,1) - 18.6;
c(:,7) = C2w(:,1) - 18.6;
c(:,8) = Mch(:,1) - 350;
ceq(1,1) = Tch(1,1) - IChT;
ceq(1,2) = Pch(1,1) - IFChP;
ceq(336,2) = Pch(336,1) - IFChP;
ceq(:,3) = C1w(:,1) - (PolyCompEff^-1).*x(:,1).*Cp_air.*C2Tin.*(CompRatio^(PolyCompExpo/(PolyCompExpo - 1)) - 1);
ceq(:,4) = Pch(:,1).*Vch./(R.*Tch(:,1)) - Mch(:,1);
ceq(:,6) = PolyTurbEff.*x(:,2).*Cp_air.*Tch(:,1).*(1-(Pch(:,1)./Pexp).^((PolyTurbExpo - 1)./PolyTurbExpo));
ceq(:,7) = EnvAirP.*CompRatio - C1P ;
ceq(:,8) = C1P(:,1).*CompRatio - C2P;
ceq(:,9) = C1Tin(:,1).*CompRatio^(PolyCompExpo./(PolyCompExpo - 1)) - C1Tout(:,1) ;
ceq(:,10) = WaterIn + HxEff.*(WaterIn - C1Tout(:,1)) - C2Tin(:,1);
ceq(:,11) = C2Tin(:,1).*CompRatio^(PolyCompExpo./(PolyCompExpo - 1)) - C2Tout(:,1) ;
ceq(:,12) = WaterIn + HxEff.*(WaterIn - C2Tout(:,1)) - HXout(:,1);
ceq(:,13) = x(:,1).*Cp_air.*( C1Tout(:,1) - C2Tin(:,1))./(Cp_water.*(WaterOut - WaterIn)) - mw1(:,1) ;
ceq(:,14) = x(:,1).*Cp_air.*(C2Tout(:,14) - HXout(:,1))./(Cp_air.*(WaterOut - WaterIn)) - mw2(:,1) ;
ceq(:,15) = mw1(:,1) + mw2(:,1) - mtw(:,1) ;
ceq(:,16) = (Mch(:,1) + (x(:,1) - x(:,2) ).*1800).*R.*x(:,1)./Vch - Pch(:,1);
end
function y = fun(x)
ncd(:,1) = C1w(:,1) + C2w(:,1) - Tow(:,1) + Ocd(:,1) - SpP(:,1).*x(:,2)./Ad(:,1).*2118.9;
y = max( ncd(:,1));
end
Errors and Warnings
Warning: The value of local variables may have been changed to match the globals. Future versions of MATLAB will require that you declare a variable to be
global before you use that variable.
> In test_4 (line 3)
Warning: The value of local variables may have been changed to match the globals. Future versions of MATLAB will require that you declare a variable to be
global before you use that variable.
> In test_4 (line 3)
Warning: The value of local variables may have been changed to match the globals. Future versions of MATLAB will require that you declare a variable to be
global before you use that variable.
> In test_4 (line 3)
Warning: The value of local variables may have been changed to match the globals. Future versions of MATLAB will require that you declare a variable to be
global before you use that variable.
> In test_4 (line 3)
Unrecognized function or variable 'EnvAirP'.
Error in test_4>fun (line 91)
C1P = EnvAirP*CompRatio;
Error in funevaluate (line 54)
f = feval(FUN,reshapeinput(Xin,X),varargin{:});
Error in poptimfcnchk (line 23)
[y,count,cache] = funevaluate(FUN,Xin,X,'init',cache,[],[],objFcnArg{:});
Error in patternsearch (line 262)
[Iterate,OUTPUT.funccount] = poptimfcnchk(FUN,nonlcon,X0,Iterate, ...
Error in test_4 (line 39)
x = patternsearch(@fun,x0,[],[],[],[],lb,ub,@nlinconst);
Caused by:
Failure in initial user-supplied objective function evaluation. PATTERNSEARCH cannot continue.
7 comentarios
Walter Roberson
el 6 de Jul. de 2020
I recommend against doing that through the nonlinear constraints.
x0 = zeros(336, 8);
lb = zeros(336,8);
ub = inf(336,8);
lb(:,8) = 700;
lb(1,8) = 2000;
lb(336,8) = 2000;
ub(:,8) = 6464;
ub(1,8) = 2000;
ub(336,8) = 2000;
A = []; b = [];
Aeq = []; beq = [];
x = patternsearch(@fun, x0(:), A, b, Aeq, beq, lb(:), ub(:), @nlinconst);
and leave out those linear constraints such as 700-Pch(:,10 from your nonlinear constraint function.
Respuestas (1)
Ebin Daniel
el 6 de Jul. de 2020
6 comentarios
Walter Roberson
el 17 de Jul. de 2020
No, you would not have to use a seperate function. Inside your const function, your last line of code is
ceq(336,2) = 2000 - Pch(336,1);
and the "end" statement that is after that is considered to be part of the same function. In the editor, right-click on the circle that is between the line number and the text area and select Set Conditional Breakpoint . In the box that comes up, put in
~all(isfinite(c)) || ~all(isfinite(ceq)) || any(imag(c) ~= 0) || any(imag(ceq) ~= 0)
and then click OK. Then run your code. If you still get the error without the breakpoint firing, then my analysis of your code is not correct.
You are calling the nonlinear constraint function correctly.
Ver también
Categorías
Más información sobre Surrogate Optimization en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!