Understanding the syntax of the minimax constraint problem

1 回表示 (過去 30 日間)
Clarisha Nijman
Clarisha Nijman 2018 年 11 月 29 日
コメント済み: Clarisha Nijman 2018 年 11 月 30 日
Dear all I am trying to solve a minimax constraint problem, where the objective function is an absolute function.
Given the data set A with 3 variables,x(1), x(2) and x(3) and an unknown error term x(4):
0.0027 0.0025 0.0025
0.0028 0.0030 0.0029
0.0030 0.0031 0.0031
0.0031 0.0031 0.0032
0.0032 0.0032 0.0033
0.0033 0.0033 0.0034
0.0035 0.0035 0.0035
0.0036 0.0032 0.0036
0.0031 0.0037 0.0037
I define the absolute function of the minimax problem:
function F = maximizefunc(A)
for i=1:size(A,1)
F(i)=A(i,1)*x(1)+A(i,2)*x(2)+A(i,3)*x(3)+x(4);
end
end
% Make a starting guess at solution
x0 = 0.1*rand(4,1);
and apply the code given in on of the last examples on the matlab site (https://nl.mathworks.com/help/optim/ug/fminimax.html)
options = optimoptions('fminimax','AbsoluteMaxObjectiveCount',5); % Minimize abs. values
[x,fval] = fminimax(@maximizefunc,x0,...
[],[],[],[],[],[],[],options);
But I am getting only errors saying:
Function definitions in a script must appear at the end of the file.
Move all statements after the "maximizefunc" function definition to before the function definition.
Error in fminimax (line 351)
user_f = feval(funfcn{3},x,varargin{:});
Does anyone have a suggestion for me? I do not really understand how the option function should be constructed. Can somebody give me some feedback pls.
Thank u in advance

回答 (1 件)

Alan Weiss
Alan Weiss 2018 年 11 月 29 日
Your problem is that you want to include a data matrix A as extra data, but you are doing it incorrectly. See Passing Extra Parameters. Your function should look like this:
function F = maximizefunc(x,A)
% code here
end
Then you call it like this:
[args] = fminimax(@(x)maximizefunc(x,A),[more args])
Alan Weiss
MATLAB mathematical toolbox documentation
  1 件のコメント
Clarisha Nijman
Clarisha Nijman 2018 年 11 月 30 日
Would I get the same result as in example below? (https://nl.mathworks.com/help/optim/ug/fminimax.html).
Find values of x that minimize the maximum value of
[f1(x), f2(x), f3(x), f4(x), f5(x)]
where
f1(x)=2x1^2+x2^248x140x2+304,
f2(x)=x1^2−3x2^2,
f3(x)=x1+3x218,
f4(x)=x1x2,
f5(x)=x1+x28.
First, write a file that computes the five functions at x.
function f = myfun(x)
f(1)= 2*x(1)^2+x(2)^2-48*x(1)-40*x(2)+304; % Objectives
f(2)= -x(1)^2 - 3*x(2)^2;
f(3)= x(1) + 3*x(2) -18;
f(4)= -x(1)- x(2);
f(5)= x(1) + x(2) - 8;
Next, invoke an optimization routine.
x0 = [0.1; 0.1]; % Make a starting guess at solution
[x,fval] = fminimax(@myfun,x0);
The only difference is that my objective function is an absolute fucntion, so I combine the next instruction on that same wegpage with more instructions above.
instructions:
You can solve problems of the form
min x max i |Fi(x)|
by using the AbsoluteMaxObjectiveCount option; see Notes.
The information needed for the set of F functions can be retrieved from the given data set A,

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLinear Algebra についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by