how to define sqrt in Optimization?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
kanuri venkata mohana
el 31 de Ag. de 2020
Respondida: Walter Roberson
el 2 de Sept. de 2020
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.
0 comentarios
Respuestas (2)
Alan Weiss
el 1 de Sept. de 2020
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
0 comentarios
Walter Roberson
el 2 de Sept. de 2020
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()
0 comentarios
Ver también
Categorías
Más información sobre Linear Programming and Mixed-Integer Linear Programming en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!