How to use a function within optiproblem?

조회 수: 1 (최근 30일)
Anthony Sirico
Anthony Sirico 2021년 12월 1일
답변: Akshat Dalal 2024년 4월 18일
My minimization function is:
pi = x(1)+x(2)-rho*min(0,x(1)^2+x(2)^2
how can i use this equation in optimproblem?
prob = optimproblem("Objective",x(1)+x(2)-rho*min(0,x(1)^2+x(2)^2),"ObjectiveSense","minimize");
x0.x = [0;0];
Error using min
Invalid data type. Second argument must be numeric or logical.
  댓글 수: 1
Matt J
Matt J 2021년 12월 1일
Note that min(0,x(1)^2+x(2)^2) will always be 0, so it is not contributing anything to the objective function.

댓글을 달려면 로그인하십시오.

답변 (1개)

Akshat Dalal
Akshat Dalal 2024년 4월 18일
Hi Anthony,
The error you're encountering is due to the way "min" function is being used within the "optimproblem" context. The "min" function expects its arguments to be numeric or logical arrays, but when defining an optimization problem symbolically, you're dealing with symbolic expressions or optimization variables, which are not directly compatible within MATLAB functions such as the "min" function.
However, as Matt already mentioned, your minimization function is independent of the "min" function as the second argument is a sum of two square numbers which is always greater than or equal to zero. Thus your function can be reduced to "x(1)+x(2)" which should work with as desired.
Hope this helps!

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by