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
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Nonlinear Optimization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!