Reputation: 3
I want to minimise the maximum value the function f(a,b,c)
takes over the range l <= c <= u
for some lower and upper bounds l
and u
by changing the parameters a
and b
. I think I will need a double iteration but beyond that I have no idea how to begin.
I would greatly appreciate any of: an answer, help in phrasing this more clearly or information about where I can look to find the answer myself. I have tried to look elsewhere for an answer, but I am struggling to know what to search for.
EDIT: As an example, suppose f(a,b,c)
is abs(g(a,c)-b)
. I have tried to vary a
so that p(a) = max(g(a,c)) - min(g(a,c))
is minimised over c
which would then easily allow me to compute what b
should be, but the problem I am having is that g
is not necessarily an easy to work with function.
Upvotes: 0
Views: 326
Reputation: 38052
If you have the optimization toolbox, use fmincon
:
X = fmincon(@(X) max(g(X(1),X(3))) - min(g(X(1),X(3))),... % the "cost function", i.e., what you want to minimize
[0 0 1],... % an initial guess for [a b c]
[],[], [],[],... % (irrelevant for your problem)
[-inf -inf 1], [+inf +inf u]); % lower and upper bounds for [a b c]
If you don't have the optimization toolbox, you can use my fminsearch
wrapper minimize
in exactly the same way. minimize
uses fminsearch
(which is included in standard MATLAB), but fminsearch
cannot handle constraints, and minimize
can.
What's more, that "initial estimate" can be hard to come by. You can do a simple grid search (as you suggested), but that tends to be tedious and slow, especially for larger problems. minimize
can run without an initial estimate, in which case it will try an optimization a bunch of times for a bunch of random initial values within the bound constraints, and return the best one.
Upvotes: 0
Reputation: 373
You can use fminsearch and add a large negative value to out-of-bound solutions:
% Your input
f = @(a,b,c) (a-2).^2+(b.^2-9)^2+sin(2*pi*c).^2;
u = 0.7;
l = -0.01;
% function to optimize
f2 = @(a) abs(f(a(1),a(2),a(3))+1e15*(a(3)>u|a(3)<l));
% Find a minima
fminsearch(f2,[1.6 1 0.2])
Upvotes: 1