I have an optimization problem like below:

$\text{minimize } - \sum_k w_k \log r_k$

$ a \leq r_k \leq b_k, k = 1, \cdots, 10$

Here, $w $ and $b$ is a set of constant: $w = [w_1, \cdots, w_{10}]$ and $b = [b_1, \cdots, b_{10}]$. Also $a$ is a constant too.

Now I want to simulate this problem. I can create a random array for $w$ and $b$, and then assign values to each $w_k$, $b_k$ using below code:

Array[(x[#] = RandomReal[1]) &, 10];
Definition @ x

But then how can I write the $\textbf{Nminimize}$ command so that it optimizes for all 10 equations? My question is, do I have to write all the equations? This is important because if I want to simulate with 100 constraints then it is not possible to write all the constraints. Is there any smart way in Mathematica to do this?


1 Answer 1

w = RandomReal[{0, 1}, 10];
b = RandomReal[{0.5, 1}, 10];
a = RandomReal[{0, .5}];

rr = Array[r, 10];
Minimize[{w.Log@rr, Thread[a <= rr <= b]}, rr]
  • $\begingroup$ Just what I am looking for. thanks @belisarius. but in the last line, is it '<' or 'greater or equal to sign'? $\endgroup$
    – jhon_wick
    Commented Aug 21, 2015 at 4:30
  • $\begingroup$ I just want to add two things (1) what if I add another constraint? Say I have a constraint: {2*rr < 3}. Do I have to write it like : Minimize[{w.Log@rr, Thread[a < rr < b, 2*rr < 3]}, rr] ?? (2) Is there any way I can view this graphically? thanks. $\endgroup$
    – jhon_wick
    Commented Aug 21, 2015 at 4:31
  • 1
    $\begingroup$ @dont_give_up Please evaluate Thread[a < rr < b, 2*rr < 3] on your front end and look at the result. Then evaluate Thread[2*rr < 3].Then search the docs for Join[ ]:D $\endgroup$ Commented Aug 21, 2015 at 4:50
  • $\begingroup$ I could not understand the use of Join[ ]. My question is: what if I have some other constraints? For the above problem there was only one but how should I add another if there were another constraints. thanks for replying. really appreciate your help. $\endgroup$
    – jhon_wick
    Commented Aug 22, 2015 at 0:23

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.