I'm trying to find the minimun value of Etot with respect to the variables bvalue and cvalue. bvalue has a range set by two constants bmin and bmax. But cmin, cmax are values with respect to bvalue.
How can I change this code to get the minimum value of Etot and the corresponding avalue, bvalue?
(* range of b *)
Clear[a, a00, b, b00, c, c00, z0, \[Beta], v0, v1, Etot, Ea, Eb, Eg, \
\[Gamma]lv, k, g, \[Rho], avalue, bvalue, bmin, bmax, cvalue, cmin, \
cmax, z0value, z1, sol1, sol2, S1, S2, S3, r]
Off[Reduce::ratnz];
Off[Solve::ratnz];
\[Beta] = 135000;
v0 = 5*10^-9;
\[Gamma]lv = 72.5*10^-3;
k = 0.94;
g = 9.8;
\[Rho] = 1000;
(*
bvalue=1.09\[Times]10^-3;
cvalue=0.82\[Times]10^-3;
*)
sol1 = Reduce[{a/b^2 + 1/a == (2 b)/a^2 +
2/3 \[Beta] b && (3 v0)/(4 \[Pi] a^2) <
b < (3 v0)/(2 \[Pi] a^2)}, a, Reals];
{a, {bmin, bmax}} =
N[sol1] /. {HoldPattern[
And[_[b1_, ___, b2_], a == a0_]] :> {a0, {b1, b2}}};
afn[b0_] := a /. b -> b0;
avalue = afn[bvalue];
v1fn[a_, b_] := 2/3 \[Pi] a^2 b;
v1 = v1fn[avalue, bvalue];
(* range of c *)
sol2 = Part[
Solve[v0 ==
2/3 \[Pi] avalue^2 bvalue + 2/3 \[Pi] avalue^2 cvalue -
1/3 \[Pi] avalue^2/cvalue^2 (2 cvalue^3 - 3 cvalue^2 z0 + z0^3),
z0], 2];
{cmin, cmax} = {3/(2 \[Pi] avalue^2) (v0 - v1), bvalue};
z1 = z0 /. sol2;
z0fn[c0_] := z1 /. c -> c0
z0value = z0fn[cvalue];
(*Gibbs evergy from here *)
r[a_, c_, z0_] := a (1 - z0^2/c^2)^(1/2);
e[x_, y_] := (1 - (y/x)^2)^(1/2)
\[Eta][x_, y_, z_] := ((e[x, y] x z)^2 + y^4)^(1/2)
S[x_, y_, z_] := \[Pi]/(
y^2 e[x, y]) (y^2 (e[x, y] x^2 + y^2 Log[e[x, y] x y + x y]) -
e[x, y] x z \[Eta][x, y, z] -
y^4 Log[e[x, y] x z + \[Eta][x, y, z]])
S1 = S[avalue, bvalue, 0];
S2 = S[avalue, cvalue, 0];
S3 = S[avalue, cvalue, z0value];
(* the energies and the values of a,b,c,z0 *)
Ea = \[Gamma]lv (S1 + S2 - S3)
Eb = \[Gamma]lv \[Pi] r[avalue, cvalue, z0value]^2 k
Eg = \[Rho] g (2/3 \[Pi] avalue^2 bvalue (3/8 bvalue + z0value) +
1/12 \[Pi] avalue^2/bvalue^2 z0value^2 (6 cvalue^2 - z0value^2))
Etot = Ea + Eb + Eg
{avalue, bvalue, cvalue, z0value};
{bmin, bmax, cmin, cmax};
(* Energy Minimization*)
f[b_?NumericQ,c_?NumericQ]:=Etot/.{bvalue\[Rule]b,cvalue\[Rule]c};
cm[b_]:=cmin/.bvalue\[Rule]b;
cmx[b_]:=cmax/.bvalue\[Rule]b;
f[0.00109,0.00082]
NMinimize[{Re[f[bvalue,cvalue]],cm[bvalue]<cvalue<cmx[bvalue]},{{\
bvalue,bmin,bmax},cvalue}]
The problem is that the output of f[0.00109,0.00082]
gives me a complex number when it should be same with when I put in the commented out avalue, bvalue(towards the top of the code when I define variables.
The output of Minimize gives me {-0.0597908, {bvalue -> 0.00122385, cvalue -> 2.16242*10^-11}}
. The expected answer is something close to;
bvalue=1.09\[Times]10^-3;
cvalue=0.82\[Times]10^-3;
Etot=1.06856*10^-6;