Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I have a function $f(x,y,z)$ I want to find the minimum/maximum of the function with some constraints like

$$0 < x < C_1$$ $$0 < y+z <C_2$$

where $C_1$ and $C_2$ are some integer constants.

Right now the function that I have is $ax + by + cz\;$ ($a,$ $b$ and $c$ are constants). But is there a generic way to do this in Matlab.

share|improve this question
    
By "generic" do you mean you want a method which will work for a not necessarily linear function? As far as I know, algorithms usually find only local maxima/minima. –  Xabier Domínguez Apr 3 '12 at 22:11
    
yes that is what i mean by generic –  Ankit Apr 4 '12 at 14:47
add comment

1 Answer 1

up vote 2 down vote accepted

You can use linprog (help page has good examples):

x = linprog(f,A,b,Aeq,beq,lb,ub) defines a set of lower and upper bounds on the design variables, x, so that the solution is always in the range lb ≤ x ≤ ub. Set Aeq = [] and beq = [] if no equalities exist.

f, x, b, beq, lb, and ub are vectors, and A and Aeq are matrices.

So

f = [a; b; c]

lb = []

ub = []

Aeq = []

beq = []

We need to setup the constraints in a matrix format $A{\mathbf x} \le b -\epsilon$. Separate $0 < x < c$ into $-x < 0,$ and $x < c,$ etc. Subtract eps to $-x < 0 -\epsilon,$ etc. So $$ \begin{pmatrix} 1 & 0 & 0 \\ 0 & -1 & 0 \\ 0 & 1 & 1 \\ 0 & -1 & -1 \end{pmatrix} \begin{pmatrix} x \\ y \\ z \end{pmatrix} \le \begin{pmatrix} c_1 -\epsilon \\ 0 -\epsilon \\ c_2 -\epsilon \\ 0 -\epsilon \end{pmatrix} $$ Now, we can invoke: linprog.

share|improve this answer
    
Hi, I looked at the documentation of fmincon here (mathworks.com/help/toolbox/optim/ug/fmincon.html). It says that fmincon is for non-linear functions. –  Ankit Apr 4 '12 at 15:04
1  
@Ankit Ops, then use linprog (mathworks.com/help/toolbox/optim/ug/linprog.html) and specify all your inequalities the same way I described. –  user2468 Apr 4 '12 at 15:30
    
can you please update the answer to include linprog so that I can accept the answer. –  Ankit Apr 4 '12 at 17:26
    
Done. Updated my answer. –  user2468 Apr 4 '12 at 18:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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