I want to minimize the function fcc
. When fcc
is calculated for a specified point the answer is correct:
In[70]:= fcc[0.5, 0.5, 0.004, 0.006, 0.0025, 0.5]
Out[70]= 2.96667*10^6
but when I want to optimize fcc
with NMinimize
there is a problem below:
NMinimize[{fcc[q1, q2, q3, q4, q5, q6], 0.5 <= q1 <= 1.5,
0.5 <= q2 <= 1.5, 0.003 <= q3 <= 0.01, 0.003 <= q4 <= 0.01,
0.002 <= q5 <= 0.005, 0.5 <= q6 <= 1}, {q1, q2, q3, q4, q5, q6}]
NDSolve::ndsv: Cannot find starting value for the variable ws. >>
ReplaceAll::reps: {NDSolve[{-((0.00011318 (q2+q3) (-0.0174073+ws[<<1>>]))/(q3 q4 q6))+(ws^[Prime])[x]==0,ws[q1]==0.012529},{ws},{x,0,q1}]} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. >>
ReplaceAll::reps: {NDSolve[{-((0.00011318 (q2+q3) (-0.0174073+ws[<<1>>]))/(q3 q4 q6))+(ws^[Prime])[x]==0,ws[q1]==0.012529},{ws},{x,0,q1}]} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. >>
ReplaceAll::reps: {NDSolve[{-((0.00011318 (q2+q3) (-0.0174073+ws[<<1>>]))/(q3 q4 q6))+(ws^[Prime])[x]==0,ws[q1]==0.012529},{ws},{x,0,q1}]} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. >>
General::stop: Further output of ReplaceAll::reps will be suppressed during this calculation. >>
NDSolve::ndsv: Cannot find starting value for the variable ts. >>
NMinimize::nnum: The function value 2.18625*10^6+6618.38 (-0.012529+ws[0]) is not a number at {q1,q2,q3,q4,q5,q6} = {1.4748,1.12029,0.0074076,0.00951558,0.00291973,0.810076}. >>
and this is the fcc
function:
ta = 30; rha = 0.4; altitude = 1361; p =
101325*(1 - altitude*2.25577*10^-5)^5.2559; tka =
273.15 + ta; c1 = -5.8002206*10^3; c2 = 1.3914993; c3 = \
-4.8640239*10^-2; c4 =
4.1764768*10^-5; c5 = -1.4452093*10^-8; c6 = 6.5459673; psata =
Exp[c1/tka + c2 + c3*tka + c4*tka^2 + c5*tka^3 + c6*Log[tka]]; pva =
rha*psata; wa =
0.621945*pva/(p -
pva); tr = 26; rsh = 1500; nu = 7.54; lef = 0.894; tsin = ta; \
tpin = ta; twin = 20; wsin = wa; wpin = wa; tkw =
273.17 + twin; psatw =
Exp[c1/tkw + c2 + c3*tkw + c4*tkw^2 + c5*tkw^3 +
c6*Log[tkw]]; pvw = psatw; wsat =
0.621945*pvw/(p -
pvw); cps = 1006; cpp = 1006; cpv = 1873; cpw = 4183; ks = \
0.027; kp = 0.027; kwater = 0.6; kwall = 237; hfg = 2501000; lwall = \
0.0005; lwater = 0.001;
fcc[lx_, ly_, lp_, mp_, mw_, ratio_] := Module[{},
ms = ratio*mp;
ls = lp;
dhs = 2*ly*ls/(ly + ls);
dhp = 2*ly*lp/(ly + lp);
hs = nu*ks/dhs;
hp = nu*kp/dhp;
hm = hs/(lef*cps);
u = 1/(1/hp + lwall/kwall + lwater/kwater);
dels = -1; delp = -1;
wss = NDSolve[{(dels hm ly (ws[x] - wsat))/ms +
Derivative[1][ws][x] == 0, ws[lx] == wsin}, {ws}, {x, 0, lx}];
tstptw =
NDSolve[{(dels ly (ts[x] - tw[x]) (hs +
cpv hm (-Evaluate[{ws[x]} /. wss] + wsat)))/(ms (cps +
cpv Evaluate[{ws[x]} /. wss])) + Derivative[1][ts][x] ==
0, (delp ly (tp[x] - tw[x]) u)/(mp (cpp + cpv wpin)) +
Derivative[1][tp][x] == 0,
1/(cpw mw)
ly (delp (-tp[x] + tw[x]) u +
dels (hs (-ts[x] + tw[x]) -
hm (hfg + cpv tw[x] -
cpw tw[x]) (Evaluate[{ws[x]} /. wss] - wsat))) +
Derivative[1][tw][x] == 0, ts[lx] == tsin, tp[lx] == tpin,
tw[0] == twin}, {ts, tp, tw}, {x, 0, lx}];
(*Plot[Evaluate[{{ts[x],tp[x],tw[x]}/.tstptw}],{x,0,lx}]*)
tpout = Evaluate[tp[0] /. tstptw]; tpout = tpout[[1]];
tsout = Evaluate[ts[0] /. tstptw]; tsout = tsout[[1]];
wsout = Evaluate[ws[0] /. wss]; wsout = wsout[[1]];
cp = 1006;
If[(tr - tpout) < 0.5, mt = 20, mt = rsh/(cp*(tr - tpout))];
np = Round[mt/mp];
ca = 100;
at = lx*((np + 1)*(ly + 4*lp) + ly);
n = 0.6;
cinv = ca*at^n;
kel = 120;
kw = 1.5;
\[Tau] = 3000;
\[Eta] = 0.5;
ro1 = 1.17;
v1 = ms/(ro1*ls*ly);
miu1 = 10^-5;
re1 = ro1*v1*dhs/miu1;
\[Alpha]1 = ls/ly;
f1 = 24*(1 - 1.355*\[Alpha]1 + 1.9467*\[Alpha]1^2 -
1.7012*\[Alpha]1^3 + 0.9564*\[Alpha]1^4 - 0.2537*\[Alpha]1^5)/
re1;
dps = 2*f1*ro1*(v1^2)*lx/dhs;
smd = 1.17;
mst = ms*np/smd;
cos = kel*\[Tau]*((dps*mst)/(\[Eta]*10^6));
ro2 = 1.17;
v2 = ms/(ro2*lp*ly);
miu2 = 10^-5;
re2 = ro2*v2*dhp/miu2;
\[Alpha]2 = lp/ly;
f2 = 24*(1 - 1.355*\[Alpha]2 + 1.9467*\[Alpha]2^2 -
1.7012*\[Alpha]2^3 + 0.9564*\[Alpha]2^4 - 0.2537*\[Alpha]2^5)/
re2;
dpp = 2*f2*ro2*(v2^2)*lx/dhp;
pmd = 1.17;
mpt = mp*np/pmd;
cop = kel*\[Tau]*((dpp*mpt)/(\[Eta]*10^6));
h = 2;
g = 9.81;
copump = kel*\[Tau]*h*g*mw*np/\[Eta];
ew = ms*np*(wsout - wsin);
cow = kw*\[Tau]*3.6*ew;
r = 0.1;
y = 10;
a = r/(1 - (1 + r)^(-y));
a*cinv + cos + cop + copump + cow];