# Simulating an optimization problem

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:

SeedRandom;
Array[(x[#] = RandomReal) &, 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

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]

• Just what I am looking for. thanks @belisarius. but in the last line, is it '<' or 'greater or equal to sign'? – jhon_wick Aug 21 '15 at 4:30
• 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. – jhon_wick Aug 21 '15 at 4:31
• @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 – Dr. belisarius Aug 21 '15 at 4:50
• 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. – jhon_wick Aug 22 '15 at 0:23