Understanding the syntax of the minimax constraint problem
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponses (1)
Alan Weiss
le 29 Nov 2018
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
Voir également
Catégories
En savoir plus sur Linear Algebra dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!