how to define sqrt in Optimization?

조회 수: 5 (최근 30일)
kanuri venkata mohana
kanuri venkata mohana 2020년 8월 31일
답변: Walter Roberson 2020년 9월 2일
HI,
I would like to implemet sqrt and round functions in optimization. Can anyone help me how to do that?
objoptim=clOptimization;
w=opt(objoptim);
classdef clOptimization
properties
P=optimvar('P',2)
end
methods
function w=opt(obj)
y=obj.P(1);
z=sqrt(y*obj.P(2));
w=round(y*z);
end
end
end
This is just an example to know the syntax. Can anyone help me.

답변 (2개)

Alan Weiss
Alan Weiss 2020년 9월 1일
I'm not sure what you are talking about. If you are trying to extend the problem-based method, then the short answer is you are on your own, there is no documented way to extend the problem-based functions. If you are talking about something else, then please describe what you are trying to do in more detail.
Alan Weiss
MATLAB mathematical toolbox documentation

Walter Roberson
Walter Roberson 2020년 9월 2일
sqrt() is already defined for optimization expressions, at least in R2020a.
>> A = optimvar('A')
A =
OptimizationVariable with properties:
Name: 'A'
Type: 'continuous'
IndexNames: {{} {}}
LowerBound: -Inf
UpperBound: Inf
See variables with show.
See bounds with showbounds.
>> sqrt(A)
ans =
Nonlinear OptimizationExpression
sqrt(A)
Be careful though, as sqrt() is not differentiable at 0.
I do not currently see any way to achieve round() using the supported functions.
round() is not differentiable at integers (and has a derivative of 0 at real values that are not integers).
Remember that the underlying optimization algorithms assume differentiability for any variable not marked as integer.
The supported integer constraints involve using intlinprog() solver, which does not support non-linear objectives -- the objective must be resolvable to a matrix multiplication, not to a generalized function.
If you need a generalized function as the objective, then you cannot turn it into an effectively integer-constraint problem by using round(): the optimization functions will fail badly on it, thinking that the objective function is flat near the integer locations.
If you need non-linear functions plus integer constraints, then you should be using ga() or gamultiobj() or paretosearch()

카테고리

Help CenterFile Exchange에서 Linear Programming and Mixed-Integer Linear Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by