Multi-variable fminsearch: Not enough input arguments
显示 更早的评论
I am getting 'Not enough input arguments' as result. Need help.
Function:
function qout = Lobo(d0, L, Tg, nb, uo)
clc
%Fuel flowrate
Ti = 251.9 + 273.15; %Fluid in degK
T0 = 386.1 + 273.15; %Fluid/gas out degK
cpL = 0.32; %Cp fluid KJ/kgdegK
flowL = 500; %flowrate fluid kg/s
THD = flowL.*cpL.*(T0 - Ti);%Total Heat Duty
Ef = 0.9320; %Fuel efficiency
qfuel = THD./Ef;%Heat released by fuel Kw
LHV = 41.05; %Fuel value KJ/kg
mfuel = qfuel./LHV;
%absorptivity
hp = 6.626*(10^-34); %planck's constant m2kg/s
cl = 3*(10^8); %speed of light m2/s
lamda = hp*cl/qfuel; %wavelength
Avog = 6.023*10^24; %Avogadro's number
x1 = 0.9;
M1 = 16;
x2 = 0.1;
M2 = 29;
fatmass = x1*M1 + x2*M2; %fuel molecular mass
nA = mfuel*Avog*fatmass; %number of atoms
pi = 22/7;
alpha = 4.*pi.*nA./lamda;
%Exchange factor
x = pi.*d0/2; %ctc
F = ((sqrt(x.^2 - 4) - x + 2.*sinh(2./x))/2.*pi);
%Heat transfer coefficient
k = 0.25*10^-3; %Thermal conductivity
%rof = 1320; %density
Gm = 920880; %mass flowrate
mu = 130; %Viscosity Pa-s
A0 = pi.*d0.*d0./4;
h0 = ((d0./k).*(0.023.*((Gm.*d0./mu.*A0).^0.8).*((cpL.*mu./k)).^0.3));
%Tube wall temperature
Tref = 41; %Ambient
Tw = Tref + (Ti - T0)/L;
%Air
ea = 0.15; %excess air
cpair = 0.171; %Kcal/kgdegK
Tairin = 114;
atfr = 1.344; %in notebook
mair = mfuel.*atfr.*(1+ea);
%Flame calculation
cpsteam = 4.1855;
cpco2 = 0.918;
cpn2 = 1.044;
xco2 = 0.054;
xsteam = 0.034; %Total should be 8.8
xn2 = 0.66;
cpgas = xsteam.*cpsteam + xco2.*cpco2 + xn2.*cpn2;
kgas = 0.25; %Thermal conductivity
mgas = mfuel + mair;
Lf = 0.0042.*(qfuel.^0.478); %flame length
tf = sqrt(pi.*uo.*Lf.*cpgas./mgas.*kgas); %flame size
db = 1.5.*tf; %Burner tile diameter
dbc = db./(sin(180./nb) + (pi./nb)); %Burner circle diameter
%Cold plane area
cbt = (qfuel.*1.055/4*10^6) + 1.5;
dtc = cbt + dbc; %tube circle diameter
ntubes = pi.*dtc./x;
Ar = L.*ntubes.*x;
%Radiant heat flux
stef = 5.67*10^-8; %Stefan-Boltzmann constant
qr = stef.*alpha.*F.*(Tg.^4 - Tw.^4) + ho.*(Tg - Tw);
%qr = stef*alpha*((sqrt((pi*d0)^2 - 16) - 2*x + 2*sinh(4/pi*d0))/4*pi)*(Tg^4 - (Tref + (Ti - T0)/L)^4) + ((d0/k)*(0.023*((Gm*d0/mu*pi*d0*d0/4)^0.8)*((cpL*mu/k))^0.3))*(Tg - (Tref + (Ti - T0)/L));
%Heat leaving
Qr = qr .* Ar; %total radiant heat absorbed
%Qr = qr * L*pi*(((qfuel*1.055/4*10^6) + 1.5) + ((1.5*(sqrt(pi*uo*Lf*cpgas/mgas*kgas)))/(sin(180/nb) + (pi/nb))));
qair = mair.*cpair.*(Tairin - Tref);
qloss = 0.05.*qfuel;
qout = qfuel + qair - ((stef.*alpha.*((sqrt((pi.*d0).^2 - 16) - 2.*x + 2*sinh(4/pi.*d0))/4*pi).*(Tg.^4 - (Tref + (Ti - T0)/L).^4) + ((d0/k).*(0.023.*((Gm.*d0/mu.*pi.*d0.*d0/4)^0.8).*((cpL.*mu./k)).^0.3)).*(Tg - (Tref + (Ti - T0)/L)).*L.*pi.*(((qfuel.*1.055/4*10^6) + 1.5) + ((1.5.*(sqrt(pi.*uo.*Lf.*cpgas./mgas.*kgas)))/(sin(180/nb) + (pi/nb))))) + qloss);
end
Solution:
%d0 = 0.01:1;
%L = 1:18;
%Tg = 1:1950;
%nb = 8:12;
%uo = 1:50;
x0 = [0.01, 1, 10, 8, 1];
options = optimset('PlotFcns',@optimplotfval);
X = fminsearch(@Lobo, x0, options);
qr = @Lobo;
plot (d0,qr)
xlabel('Tube circle diameter (d0)');
ylabel('flux (qr)');
回答(1 个)
Walter Roberson
2018-3-7
X = fminsearch(@Lobo, x0, options);
invokes Lobo with one input vector which is the same length as x0.
You probably want
X = fminsearch(@(x) Lobo(x(1),x(2),x(3),x(4),x(5)), x0, options);
22 个评论
Devdatt Thengdi
2018-3-7
Devdatt Thengdi
2018-3-7
Devdatt Thengdi
2018-3-8
Devdatt Thengdi
2018-3-8
Devdatt Thengdi
2018-3-8
Torsten
2018-3-8
If you want to put constraints on some of your design variables, use "fmincon" instead of "fminsearch".
Best wishes
Torsten.
Devdatt Thengdi
2018-3-8
Walter Roberson
2018-3-8
fmincon, non-linear constraint function. qr can be calculated from the inputs so it can be constraint by a non-linear constraint function.
I suggest extracting all of the logic used to calculate qr into a function that you call from both the objective function and the nonlinear constraint function. This might involve calculating other variables as well in order to be able to calculate qr.
Torsten
2018-3-8
But qr is a function of the design variables, say qr = f(x1,...,x5), so you can constrain it by using the nonlinear constraint function of fmincon to set f(x1,...,x5) <= some value.
Devdatt Thengdi
2018-3-8
Devdatt Thengdi
2018-3-8
Torsten
2018-3-8
function [c,ceq] = nonlcon(d0, L, Tg, nb, uo)
%Fuel flowrate
Ti = 251.9 + 273.15; %Fluid in degK
T0 = 386.1 + 273.15; %Fluid/gas out degK
cpL = 0.32; %Cp fluid KJ/kgdegK
flowL = 500; %flowrate fluid kg/s
THD = flowL.*cpL.*(T0 - Ti);%Total Heat Duty
Ef = 0.9320; %Fuel efficiency
qfuel = THD./Ef;%Heat released by fuel Kw
LHV = 41.05; %Fuel value KJ/kg
mfuel = qfuel./LHV;
%absorptivity
hp = 6.626*(10^-34); %planck's constant m2kg/s
cl = 3*(10^8); %speed of light m2/s
lamda = hp*cl/qfuel; %wavelength
Avog = 6.023*10^24; %Avogadro's number
x1 = 0.9;
M1 = 16;
x2 = 0.1;
M2 = 29;
fatmass = x1*M1 + x2*M2; %fuel molecular mass
nA = mfuel*Avog*fatmass; %number of atoms
pi = 22/7;
alpha = 4.*pi.*nA./lamda;
%Exchange factor
x = pi.*d0/2; %ctc
F = ((sqrt(x.^2 - 4) - x + 2.*sinh(2./x))/2.*pi);
%Heat transfer coefficient
k = 0.25*10^-3; %Thermal conductivity
%rof = 1320; %density
Gm = 920880; %mass flowrate
mu = 130; %Viscosity Pa-s
A0 = pi.*d0.*d0./4;
h0 = ((d0./k).*(0.023.*((Gm.*d0./mu.*A0).^0.8).*((cpL.*mu./k)).^0.3));
%Tube wall temperature
Tref = 41; %Ambient
Tw = Tref + (Ti - T0)/L;
%Air
ea = 0.15; %excess air
cpair = 0.171; %Kcal/kgdegK
Tairin = 114;
atfr = 1.344; %in notebook
mair = mfuel.*atfr.*(1+ea);
%Flame calculation
cpsteam = 4.1855;
cpco2 = 0.918;
cpn2 = 1.044;
xco2 = 0.054;
xsteam = 0.034; %Total should be 8.8
xn2 = 0.66;
cpgas = xsteam.*cpsteam + xco2.*cpco2 + xn2.*cpn2;
kgas = 0.25; %Thermal conductivity
mgas = mfuel + mair;
Lf = 0.0042.*(qfuel.^0.478); %flame length
tf = sqrt(pi.*uo.*Lf.*cpgas./mgas.*kgas); %flame size
db = 1.5.*tf; %Burner tile diameter
dbc = db./(sin(180./nb) + (pi./nb)); %Burner circle diameter
%Cold plane area
cbt = (qfuel.*1.055/4*10^6) + 1.5;
dtc = cbt + dbc; %tube circle diameter
ntubes = pi.*dtc./x;
Ar = L.*ntubes.*x;
%Radiant heat flux
stef = 5.67*10^-8; %Stefan-Boltzmann constant
qr = stef.*alpha.*F.*(Tg.^4 - Tw.^4) + ho.*(Tg - Tw);
% Set constraints
ceq = [];
c(1) = qr - 45000; % qr <= 45000
c(2) = -qr + 32000; % qr >= 32000
end
Walter Roberson
2018-3-8
That code uses the undefined variable ho . Perhaps you mean h0 ?
In the line
cbt = (qfuel.*1.055/4*10^6) + 1.5;
could you verify that you want to take 1.055, divide by 4, and multiply the result by 10^6? Or did you want to divide by (4*10^6) ?
Why are you using
pi = 22/7
when more accurate versions are easily available?
Devdatt Thengdi
2018-3-10
Devdatt Thengdi
2018-3-10
Walter Roberson
2018-3-10
MATLAB predefines pi (lowercase, just like you used) to be the most accurate representation of π possible in double precision
Devdatt Thengdi
2018-3-11
Walter Roberson
2018-3-11
Your line
X = fmincon(@(x)Lobo(x(1),x(2),x(3),x(4),x(5)), x0, [], [], [], [], [], [], @(c)Lobo(c(1), c(2)), options);
tries to use your objective function, Lobo, as also being the nonlinear constraint function. But the nonlinear constraint function needs to have two outputs and Lobo only has one output, so you cannot use Lobo there. You should be calling your nonlcon in that position before options. And make sure you pass in all of the arguments that your nonlcon needs -- your anonymous function is only passing in the first two elements of the parameters but your nonlcon expects 5 inputs.
Devdatt Thengdi
2018-3-13
Torsten
2018-3-13
Set F=[F1,-F2] - then both functions F1 and F2 are to be minimized.
Best wishes
Torsten.
类别
在 帮助中心 和 File Exchange 中查找有关 Surrogate Optimization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!