optimization using fminimax not enough input arguments

Hello,
I have the following example that I need to model on Matlab.
I am using the function fminimax to retrieve values for u and v to characterize my controller. I was asked to find find the minmax of the Hamiltonian function which will lead to the derivatives written below and using these derivatives, matlab will supposedly give me values for x, u and v. So far, I have written the following code, but I am always getting the error "not enough input arguments". How can I use fminimax to find the values of x, u and v?

1 Comment

Your Game.m requires that a variable named T be already defined, so we cannot test your code.

Sign in to comment.

Answers (2)

x0=[30; 0; 25; 0];
ub=[100; 10000; 100; 100];
lb=[0; 0; 0; 0];
result=fminimax(@myfun,x0,ub,lb);
fminimax has the full calling sequence
X = fminimax(FUN,X0,A,B,Aeq,Beq,LB,UB,NONLCON,OPTIONS)
You can omit starting from the right hand side -- for example it would be valid to call
X = fminimax(FUN,X0,A,B,Aeq,Beq,LB,UB)
However, because parameters are positional in MATLAB, you cannot omit parameters in the middle and still hope to have MATLAB understand you. If you want to pass LB and UB and do not need A, B, Aeq, Beq, then you need to pass [] in the positions of the parameters you do not need:
result=fminimax(@myfun,x0, [], [], [], [], ub,lb);
Meanwhile, you have
function [H] = myfun(T, Q, Tff, lambda)
so myfun needs to be passed 4 parameters, but fminimax will only pass a single parameter (the documentation refers to it as x ) .
Notice the part of the fminimax documentation that says,
Passing Extra Parameters explains how to pass extra parameters to the objective functions and nonlinear constraint functions, if necessary.

6 Comments

Hello, thank you for your fast response.
I fixed the calling sequence. However, in regards to the parameters, I have attached a new file I would like you to take a look at. It only involves x, u, v and lamda. However, x, u and v are all unknowns and not parameters. They are a function of several variables (Q, Tf, T) and I need the fminimax function to find a value for x, u, v and lambda so that I can calculate the value of these variables.1.PNG
function [H] = myfun(xuvl)
x = xuvl(1);
u = xuvl(2);
v = xuvl(3);
lambda = xuvl(4);
xs=30;
H=(x-xs).^2+lambda.*(v-x+u);
end
Notice, however, that if you increase v by dv and decrease u by dv then v-x+u remains the same. Therefore unless there are additional calculations that favour one v over a different v, you would have a line of solutions rather than a single solution.
Hello and thanks again, I was able to finally run the code, but I faced this error message:
Local minimum possible. Constraints satisfied.
fminimax stopped because the size of the current search direction is less than
twice the default value of the step size tolerance and constraints are
satisfied to within the default value of the constraint tolerance.
<stopping criteria details>
Optimization stopped because the norm of the current search direction, 4.547473e-13,
is less than 2*options.StepTolerance = 1.000000e-06, and the maximum constraint
violation, 4.547474e-13, is less than options.ConstraintTolerance = 1.000000e-06.
That's not an error message. Error messages say "Error" somewhere.
Mathworks does not create any minimizers that are guaranteed to find the global minima of arbitrary functions. Indeed, it can be proven that it is impossible to create a function that is guaranteed to return the global minima location of arbitrary functions.
Most of the Mathworks optimization functions do not even try to find the global minima: they are local minimizers only. Even the functions such as ga() in the Global Optimization Toolbox do not promise to find the global minima, only to use some strategies that sometimes work.
Because of this, the Mathworks optimization functions that operate on abitrary objective functions never report back that they have definitely found a global minima: instead they just report back that they have found a minima, but warn that it might only be a local minima.
That is what you are seeing: you have found what appears to be a pretty decent minima, a location that is either the exact minima (to within round-off) or very close to it -- but fminimax cannot promise that for sure it is the global minima.
For example, if your function were
H = (x-xs).^2+lambda.*(v-x+u) - (x == 0.74453133950005578878261758291046135127544403076171875) * 1e100;
then at x = 0.74453133950005578878261758291046135127544403076171875 exactly the function would have a huge dip, and there is no possible way that a numeric exploration of the surface that did not happen to try 0.74453133950005578878261758291046135127544403076171875 exactly could possibly detect it.

Sign in to comment.

Thank you so very much, you have been extremely helpful! :)

1 Comment

@Vanessa, you should Accept-click Walter's answer if you are satisfied with it.

Sign in to comment.

Categories

Find more on Number games in Help Center and File Exchange

Products

Asked:

on 27 Dec 2019

Edited:

on 27 Dec 2019

Community Treasure Hunt

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

Start Hunting!