How to continue without solution min max constraint problem.

조회 수: 1 (최근 30일)
Clarisha Nijman
Clarisha Nijman 2018년 12월 14일
댓글: Clarisha Nijman 2018년 12월 15일
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
  댓글 수: 1
Matt J
Matt J 2018년 12월 14일
Please elaborate on "does not work". What's wrong with it?

댓글을 달려면 로그인하십시오.

채택된 답변

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에서 Solver-Based Nonlinear Optimization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by