# NMinimize producing error message NMinimize::bcons:

α=1.5; a=200; b = 50; θ = 0.08; β = 0.2; c1 = 600; c2 = 0.9; c3 = 2.0;
H = 4; m := 8; s[0] := 0; s[m] := H;

f11 := c1/H;

A1 = (α - 1)*((((a/θ) - (b/θ^2))*r) + ((b*(r)^2)/(2*θ)) + (((a/(\θ^2)) - (b/(θ^3)))*((E^(-θ*r)) - 1)));
B1 = (((b/(θ^3)) - ((a + b*(H - r))/(θ^2)))*(1 - (E^(θ*(H - r))))) + (((b/(θ^2)) - a)*(H - r)) - ((b*((H - r)^2))/2);
Z1 = Sum[(((((a + (b*s[i]))/θ) - (b/(θ^2)))*((E^(θ*(s[i] - t[i]))) - (1/θ))) - (((a/θ) - (b/(θ^2)))*(s[i] - t[i])) + ((b*((s[i])^2 - (t[i])^2))/(2*θ))), {i, 1, m}];

f21[m_] := (c2*(A1 + B1 - Z1))/H;

G1 = Sum[(((2*b*((E^(-β*(t[i] - s[i - 1]))) - 1))/(β^3)) + ((a + b*t[i])/(β^2)) + ((b*(E^(-β*(t[i] - s[i - 1])))*(t[i] - s[i - 1]))/(β^2)) - ((a + b*s[i - 1])*(E^(-β*(t[i] - s[i - 1])))*((1/(β^2)) + ((t[i] - s[i - 1])/β)))), {i, 1, m}];
L1 = α*((a*r) + ((b*(r)^2)/2));
P1 = Sum[(((E^(-θ* t[i]))*((((a + b*s[i])*(E^(θ*s[i]))) - ((a + b*t[i])*(E^(θ*t[i]))))/θ) - ((b*((E^(θ*s[i])) - (E^(θ*t[i]))))/(θ^2)))), {i, 1, m}];
P2 = Sum[((a + b*t[i] - ((a + b*s[i - 1])*(E^(-β*(t[i] - s[i - 1])))))/β) - ((b*(1 - (E^(-β*(t[i] - s[i - 1])))))/(β^2)), {i, 1, m}];

f31[m_] := (c3*(L1 - P1 - P2))/H;

w1[m_] := f11 + f21 + f31;

NMinimize[
{w1[m], s[i] - t[i] > 0, t[i + 1] - s[i] > 0,
{i, 1, m - 1} && t[1] > 0 && t[m] < H && r > 0 && r < H},
Join[
Flatten @ {Table[t[i], {i, 1, m}]},
Flatten  {Table[s[i], {i, 1, m - 1}]},
{r}]]


I have to find s[i] where i = 1, 2, 3, ..., m-1 and t[i] where i = 1, 2, 3, ..., m and r such that w1[m] to be minimized.

But it results in the following error

NMinimize::bcons: The following constraints are not valid: {s[i]-t[i]>0,-s[i]+t[1+i]>0,i,1,7,t[1]>0,t[8]<4,r>0,r<4}. Constraints should be equalities, inequalities, or domain specifications involving the variables.

Why shouldn't it give me the output?

• (1) This would be easier to read if formatted with the "Code Sample" icon. (2) I am guessing the issue is that the constraints are left as "symbolic" e.g. s[i] rather than explicit e.g. s[2]. The variables are explicit from a Table so the symbolic items will not be recognized as variables, – Daniel Lichtblau Mar 9 '18 at 18:38

Correct a few typing errors to get the result. For example f21[m] + f31[m]. And don't mix Andand List in conditions of NMinimize. And give explicit variables with Table like Daniel Lichtblau says.

\[Alpha] = 1.5; a = 200; b = 50; \[Theta] = 0.08; \[Beta] = 0.2; c1 = \
600; c2 = 0.9; c3 = 2.0;
H = 4; m := 8; s[0] := 0; s[m] := H;

f11 = c1/H;

A1 = (\[Alpha] -
1)*((((a/\[Theta]) - (b/\[Theta]^2))*
r) + ((b*(r)^2)/(2*\[Theta])) + (((a/(\[Theta]^2)) - (b/(\
\[Theta]^3)))*((E^(-\[Theta]*r)) - 1)));
B1 = (((b/(\[Theta]^3)) - ((a +
b*(H - r))/(\[Theta]^2)))*(1 - (E^(\[Theta]*(H -
r))))) + (((b/(\[Theta]^2)) - a)*(H -
r)) - ((b*((H - r)^2))/2);
Z1 = Sum[(((((a + (b*
s[i]))/\[Theta]) - (b/(\[Theta]^2)))*((E^(\[Theta]*(s[
i] - t[i]))) - (1/\[Theta]))) - (((a/\[Theta]) - (b/(\
\[Theta]^2)))*(s[i] -
t[i])) + ((b*((s[i])^2 - (t[i])^2))/(2*\[Theta]))), {i, 1,
m}];

f21[m_] = (c2*(A1 + B1 - Z1))/H;

G1 = Sum[(((2*
b*((E^(-\[Beta]*(t[i] - s[i - 1]))) -
1))/(\[Beta]^3)) + ((a +
b*t[i])/(\[Beta]^2)) + ((b*(E^(-\[Beta]*(t[i] -
s[i - 1])))*(t[i] - s[i - 1]))/(\[Beta]^2)) - ((a +
b*s[i - 1])*(E^(-\[Beta]*(t[i] -
s[i - 1])))*((1/(\[Beta]^2)) + ((t[i] -
s[i - 1])/\[Beta])))), {i, 1, m}];
L1 = \[Alpha]*((a*r) + ((b*(r)^2)/2));
P1 = Sum[(((E^(-\[Theta]*
t[i]))*((((a + b*s[i])*(E^(\[Theta]*s[i]))) - ((a +
b*t[i])*(E^(\[Theta]*
t[i]))))/\[Theta]) - ((b*((E^(\[Theta]*
s[i])) - (E^(\[Theta]*t[i]))))/(\[Theta]^2)))), {i, 1,
m}];
P2 = Sum[((a +
b*t[i] - ((a +
b*s[i -
1])*(E^(-\[Beta]*(t[i] -
s[i - 1])))))/\[Beta]) - ((b*(1 - (E^(-\[Beta]*(t[i] -
s[i - 1])))))/(\[Beta]^2)), {i, 1, m}];
f31[m_] = (c3*(L1 - P1 - P2))/H;

w1[m_] = f11 + f21[m] + f31[m];


result

NMinimize[{w1[m],
And @@ Flatten@
Table[{s[i] - t[i] > 0, t[i + 1] - s[i] > 0}, {i, 1, m - 1}] &&
t[1] > 0 && t[m] < H && r > 0 && r < H},
Join[Flatten@{Table[t[i], {i, 1, m}]},
Flatten [Table[s[i], {i, 1, m - 1}]], {r}]]

(*   {-108620., {t[1] -> 4.66636*10^-12, t[2] -> 1.51322*10^-11,
t[3] -> 2.73587*10^-11, t[4] -> 4.20589*10^-11,
t[5] -> 6.04899*10^-11, t[6] -> 8.51981*10^-11,
t[7] -> 1.22716*10^-10, t[8] -> 2.01536*10^-10,
s[1] -> 9.77845*10^-12, s[2] -> 2.10801*10^-11,
s[3] -> 3.4469*10^-11, s[4] -> 5.0896*10^-11,
s[5] -> 7.21611*10^-11, s[6] -> 1.02376*10^-10,
s[7] -> 1.55217*10^-10, r -> 4.}}   *)

• Thank You very much, Sir. Now it is displaying answers. But r is strictly less than 4. Also, it gives answers when m is less than or equal to 8 because it is initially fixed to 8. But, for m=9,10,11 etc, it displays 4 is not a variable. What is that 4 I don't know? – Savitha Mar 10 '18 at 18:23
• First: In your parameter definitions,you define m and s[m]. If you don't clear this, it is used for the next calculation. Prepend Clear[m,s]; to the first line. Second, I can't imagine, why r is strictly less than 4. Do Quit[] and copy and paste my code. You should get the shown result. – Akku14 Mar 11 '18 at 9:09
• Since the given conditions are r<H, r->4 means, the minimum is at r==4, but never reached. – Akku14 Mar 11 '18 at 9:18
• 4. is not the same as 4 If you look at the InputForm or FullForm of the output it shows r -> 3.999999805932165 which when displayed to 6 significant digits is r -> 4. – Bob Hanlon Apr 8 '18 at 22:20