Two-variable optimization with additional conditions
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Bogdan Nikitchuk
el 2 de Feb. de 2024
Comentada: Bogdan Nikitchuk
el 2 de Feb. de 2024
Let me describe the setup. Let us say I have two unit vectors
(all of the components are known real numbers), and
with
, and
. I also have some two-variable function
. I would like to sole the following optimization problem
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1606771/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1606776/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1606781/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1606786/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1606791/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1606796/image.png)
with the additional condition
i.e.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1606801/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1606806/image.png)
The optimization itself is not a problem, however, I have no idea how to not only solve the optimization problem but also satisfy the last condition.
2 comentarios
John D'Errico
el 2 de Feb. de 2024
It usually would be, except you should never be writing your own optimization code for your work, when it is already available. Especially if you are not an expert on the subject. Use FMINCON, as suggested. Or use other tools that allow nonlinear constraints. GA, for example.
Respuesta aceptada
Torsten
el 2 de Feb. de 2024
Editada: Torsten
el 2 de Feb. de 2024
Use "fmincon" and set the condition as a constraint in function "nonlcon".
Since you work with trigonometric functions, maybe restricting phi and theta by setting lower and upper bounds in the arrays "lb" and "ub" is an additional option.
Más respuestas (1)
Matt J
el 2 de Feb. de 2024
Editada: Matt J
el 2 de Feb. de 2024
The constraint is equivalent to minimizing over the intersection of the unit sphere and a plane through the origin (normal to n0). This is a great circle of the unit sphere. You should therefore just parametrize the great circle in terms of some angle t and then rewrite your function f() as a 1 dimensionsal function of t. This reduces the problem to a 1-variable problem with no constraints, which you can solve with fminbnd.
basis=null(n0(:).'); %basis for plane of great circle
fobj=@(t) objective(t,n0); %objective re-written as function of t
t_optimal = fminbnd( fobj , 0, 2*pi);
[~,phi,theta] = fobj(t_optimal);
function [fval,phi,theta] = objective(t,basis)
n1=basis*[sin(t);cos(t)];
[phi,theta]=cart2sph(n1(1), n1(2), n1(3));
fval=f(theta,phi);
end
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!