1
$\begingroup$

I'm using NMinimize to solve the following objective function.

S1 = 0.874334;

S2 = 0.125666;

Wd11[R_] := Exp[-((R - 6.491541)/34.9807)^1.506582];

V11[R_] := Wd11[R]*S1;

Wd12[Q_, R_] := Exp[-(((R + ((1 - 0.5)*Q)) - 14.19834)/53.64985)^1.701898];

V12[Q_, R_] := Wd12[Q, R]*S1;

Wd21[Q_, R_] := Exp[-(((R + 0.5*Q) - 13.3108)/45.07249)^1.690368];

V21[Q_, R_] := Wd21[Q, R]*S2;

Wd22[R_] := Exp[-((R - 10.4539)/39.29455)^1.617706];

V22[R_] := Wd22[R]*S2;

a := V11[R] + V12[R, Q] + V21[R, Q] + V22[R];

f[Q_] := If[1 <= Q <= 1000, 75, 
   If[1000 < Q <= 3000, 74, 
    If[3000 < Q <= 7000, 73, 
     If[7000 < Q <= 15000, 71.5, 
      If[15000 < Q <= 26000, 70.5, If[Q > 26000, 69, 0]]]]]];

T[Q_] := 850*1.6*(IntegerPart[(Q*22*0.5)/45000]) + (850*1.6*0.7^
     Log[2, 45000/(FractionalPart[(Q*0.5*22)/45000]*45000)]);

The objective function is:

OB[Q_, R_] := ((3650*f[Q]) + (3650/Q*(T[Q] + T[Q])) + (3650/
       Q (50 + 2*50)) + (0.25*
       f[Q]*(Q/2 - (0.5*10*(6 - 4)) + (R - (4*10)))) + (0.18*
       f[Q]*(3*10)))*15;

So,

NMinimize[{OB[Q, R], Q >= 1, R >= 1, a <= 0.02}, {Q, R}]

but it results in the following errors:

LessEqual::nord: Invalid comparison with 1.93457 +0.143499 I attempted. >>

NMinimize::bcons: The following constraints are not valid: {Q>=1,R>=1,0.874334 E^(-0.00113881 (-14.1983+Q+Times[<<2>>])^1.7019)+0.125666 E^(-0.00160059 (-13.3108+Q+Times[<<2>>])^1.69037)+0.125666 E^(-0.00263535 (-10.4539+R)^1.61771)+0.874334 E^(-0.00472167 (-6.49154+R)^1.50658)<=0.02}. Constraints should be equalities, inequalities, or domain specifications involving the variables. >>

I've checked this error on many pages and tried different solutions, but it still doesn't work. The problem actually arises from the third constraint (a <= 0.02). When I place a == 0.02, it gives an output, but I'm not sure if this output is correct. Anyway, why shouldn't it give me the output when a <= 0.02?

Thank you

$\endgroup$
1
  • $\begingroup$ a can be complex in your code, do you want it to be real-valued? $\endgroup$
    – Jason B.
    Commented Nov 3, 2015 at 13:38

1 Answer 1

2
$\begingroup$

The error you get is the same error you get when you evaluate 3 < 4 + 2I - you are asking if a complex number is less than a real-valued one.

Take the answer you get when you put in the equality, and then feed that back into a

NMinimize[{OB[Q, R], Q >= 1, R >= 1, a == 0.02}, {Q, R}]
(* {4.31243*10^6, {Q -> 478.281, R -> 94.4141}} *)

a /. %[[2]]
(* 0.967752 + 1.21616*10^-12 I *)

and you see it has a small imaginary part. If you demand that a be real, you get a convergence error

NMinimize[{OB[Q, R], Q >= 1, R >= 1, Re[a] <= 0.02, 
  Im[a] == 0}, {Q, R}]

During evaluation of In[--]:= NMinimize::incst: NMinimize was unable to generate any initial points satisfying the inequality constraints {-0.02+Re[0.874334 E^(-0.00113881 Power[<<2>>])+0.125666 E^(-0.00160059 Power[<<2>>])+0.125666 E^(-0.00263535 Power[<<2>>])+0.874334 E^(-0.00472167 Power[<<2>>])]<=0}. The initial region specified may not contain any feasible points. Changing the initial region or specifying explicit initial points may provide a better solution. >>

(* {4.31243*10^6, {Q -> 478.132, R -> 94.4141}} *)

which you can solve by giving an initial guess.

NMinimize[{OB[Q, R], Q >= 1, R >= 1, Re[a] <= 0.02, 
  Im[a] == 0}, {{Q, 478, 480}, {R, 90, 100}}]
(* {4.31243*10^6, {Q -> 478.287, R -> 94.4141}} *)

Notice this value is slightly higher than the previous answer, so there is a price to pay by demanding a be real.

Edit: Okay, so you wanna be sure that this is the minimum value - well, minimum on what interval? Let's just take Q and R from 1 to 1000 and find the minimum manually.

data1 = Flatten[Table[{q, r, OB[q, r], a /. {Q -> q, R -> r}}, {q, 1, 1000, 
    1}, {r, 1, 1000, 1}],1];

Select the values according to your inequality

data2 = Select[data1, (Re[#[[4]]] <= 0.02 &)];

and pick the minimum,

Sort[data2, #2[[3]] > #1[[3]] &][[1]]
(* {478, 95, 4.3126*10^6, 0.0192163} *)

which makes me trust the values found above via NMinimize

$\endgroup$
4
  • $\begingroup$ Thank you Jason. But is this result reliable? I mean, is that correct and can I use it for my analysis? $\endgroup$
    – Mahdi
    Commented Nov 3, 2015 at 14:39
  • $\begingroup$ You tell me - I have no idea what these equations mean really. Is it necessary that a be real? $\endgroup$
    – Jason B.
    Commented Nov 3, 2015 at 14:42
  • $\begingroup$ Yes, it should be. However, if the difference is that small, it doesn't matter. Moreover, you determined the initial guess by getting the results when a == 0.02. I selected an interval {Q, 100, 1000}, {R, 40, 1000} and got the same results as yours (when {Q, 478, 480}, {R, 90, 100}). But when {Q, 1, 10000}, {R, 40, 10000}, I got another result. Then, I think I can't choose any interval, right? $\endgroup$
    – Mahdi
    Commented Nov 3, 2015 at 15:05
  • $\begingroup$ I got it now. Thank you. $\endgroup$
    – Mahdi
    Commented Nov 3, 2015 at 15:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.