Linprog and Max Function
Mostrar comentarios más antiguos
Hi,
I have a question concerning the linprog-Programm in Matlab. I am trying to implement the objective function:
f(d) = Df*d + max(0, g + Dg*d)
where Df, g and Dg are just numbers. Now I am trying to use linprog to minimize this function in respect to d. However, I dont know how to implement the maximum function. I also tries to rewrite the maximum function by using the absolute function and using other methods. However my main problem is that g is suppose to be a constant that is not multiplied by d. All the methods I tried resulted in g being multiplied by d. If you can give me a hand on this, it would be great!
Thank you!
1 comentario
Austin
el 22 de Nov. de 2011
Respuesta aceptada
Más respuestas (2)
Titus Edelhofer
el 21 de Nov. de 2011
0 votos
Hi,
if Df, g and Dg are "just numbers", why would you use linprog? The function is piecwise linear, so there are only three points that come into question for realizing the minimum (the breakpoint of the max and the left and right boundary) ...?
Regarding linprog, I doubt you will get rid of the constant "g".
Titus
Teja Muppirala
el 21 de Nov. de 2011
Assuming by "just numbers" you mean "(constant) arrays", you can solve it by solving two linear programming problems.
Step 1. Solve using only Df.
[x{1},f(1)] = linprog(Df,A,b);
Step 2. Solve using Df+Dg, and add g to the result.
[x{2},f(2)] = linprog(Df+Dg,A,b);
f(2) = f(2)+g;
Step 3. The answer to your problem is the maximum of Step 1 and Step 2.
[f_answer,idx] = max(f);
x_answer = x{idx};
You can compare this to what you would get if you used FMINCON instead (though fmincon does not always converges to the right answer).
A = [eye(3); -eye(3)];
b = [1;1;1;1;1;1];
Df = randn(1,3);
Dg = randn(1,3);
g = randn;
F = @(X) Df*X + max(0,g+Dg*X);
[xo,fo] = fmincon(F,[0;0;0],A,b);
[x{1},f(1)] = linprog(Df,A,b);
[x{2},f(2)] = linprog(Df+Dg,A,b);
f(2) = f(2)+g;
[f_answer,idx] = max(f);
x_answer = x{idx};
% Compare with the result from FMINCON
[x_answer xo]
[f_answer fo]
1 comentario
Austin
el 22 de Nov. de 2011
Categorías
Más información sobre Solver Outputs and Iterative Display en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!