How to continue without solution min max constraint problem.

2 次查看(过去 30 天)
Hello,
Solving a min max constraint problem in matlab,is a part/function of my whole code. This function finds the optimal linear combination of the distributions, x and y such that it approximates z very good. The problem is that the code is terminated if the optimization problem cannot be solved. In that case I would like to use choose my own values for the optimal parameters.
So I wrote this part in the code:
%If the optimal solution is not found then:
if sum(OptArgum(1:2))<1
OptArgum(1)=0.5;
OptArgum(2)=0.5;
end
But It does not work. So now I am left with two questions:
1) Can you give me some suggestion for better code?
2) How can I add arguments to the code such as 'MaxFunEvals', 1000, 'Maxiter', 1000, such that the code is not terminated easily?
Thank you in advance
This is the code of my function:
function[OptArgum,v]=ModelParametersMinMax (x, y, z)
%This function finds the optimal linear combination of the distributions, x and y such that it approximates z very good. z=a*x+(1-a)*y
%input
% x =The pdf vector of process x
% y =The pdf vector of process y
% z =The pdf vector of all processes together
%output
%OptArgum=A vector that consist of three entrees all coefficients for x,y and z
%v =A linear combination of the x and y such that v can be approximated by: a*x+(1-a)*y
%Construction of the constraint matrix
Aleq=[];
bleq=[];
Aeq=[1 1 0];
beq=1;
%bound of the variables
lb=[0 0 0];
ub=[];
x0=0.1*rand(3,1);%initial guess
Cs=[x y -z];%coefficients of the objective function
% Solving the minmax constraint problem
[OptArgum, ~] = fminimax(@(x) Cs*x,x0,Aleq,bleq(:),Aeq,beq,lb,ub);
%If the optimal solution is not found then:
if sum(OptArgum(1:2))<1
OptArgum(1)=0.5;
OptArgum(2)=0.5;
end
v=OptArgum(1)*xPred + OptArgum(2)*xEstimatedRate;%approximation for z
end

采纳的回答

Matt J
Matt J 2018-12-14
编辑:Matt J 2018-12-14
options=optimoptions(@fminimax,__________);
% Solving the minmax constraint problem
[OptArgum, ~,~,exitflag] = fminimax(@(x) Cs*x,x0,Aleq,bleq(:),Aeq,beq,lb,ub,[],options);
%If the optimal solution is not found then:
if exitflag<=0
OptArgum(1)=0.5;
OptArgum(2)=0.5;
end
  1 个评论
Clarisha Nijman
Clarisha Nijman 2018-12-15
Thanks Matt,
This is exactly what I need, if an optimal solution is not found the whole code stops running, but now I know how to prevent that. However, I have to study the exitflag options better.
kind regards

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Nonlinear Optimization 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by