How can I write a self scaling function for fmincon ?

1 次查看(过去 30 天)
Hey,
I use fmincon and I want to maximize this function =
fun = @(x) -(x(1)*x(2)*x(3))
and now I do not want to change this function everytime I in- or decrease the size of my optimization.
For example:
If I am looking for 6 solutions my function should look like this =
fun = @(x) -(x(1)*x(2)*x(3)*x(4)*x(5)*x(6))
Is there a way to do it automatically ?
Thank you so much!

采纳的回答

Matt J
Matt J 2018-11-28
编辑:Matt J 2018-11-28
fun = @(x) -sum(log(x))
  11 个评论
Tim
Tim 2018-11-30
Ah okay. I will try this as well. One additional question came to my mind: Is my code a good way to minimize each of the objective values individually or would you suggest something else?

请先登录,再进行评论。

更多回答(1 个)

Walter Roberson
Walter Roberson 2018-11-28
@(X) -prod(X)
  2 个评论
Tim
Tim 2018-11-29
Thank you for answer! I appreciate that you are so passionate to solve my problem.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by