How to use fminbnd but with multiple variables

48 views (last 30 days)
I have a function of multiple variables defined in a specified range. They can be even vectors. I want to find the minimum of a function in that interval. The simplified example is the following:
X1=[0.001 0.5];
X2=[1 1]; %with this i mean that L1 must be in the range of 0.001 and 1, while C1 in the range of 0.5 and 1
f=@(L1,C1)sqrt(1/(L1*C1));
[X,Y]=fminbnd(f,X1,X2)
Naturally here it doesn't work. Is there a possible alternative solution to this problem? Thanks in advance

Accepted Answer

John D'Errico
John D'Errico on 15 Jul 2023
Edited: John D'Errico on 15 Jul 2023
You CANNOT use fminbnd with vectors. Period. A vector of numbers is not a function. Often people think of a vector as a function. But it is not. It is just a list of values, perhaps sampled from some function. Even though, at some time, a function was involved in the creation of that vector of values, a vector is not a function. So remember, fminbnd applies ONLY to a numeric function. (It also does not apply to symbolic problems, so you cannot use it with syms variables. You could use matlabFunction to convert a one variable problem to an anonymous function, then use a solver on that.)
Next, fminbnd applies only to functions of ONE variable. If you have two or more independent variables, then you need to use some other optimization tool. Perhaps fminsearch, or if you have the optimization toolbox, you can use fminunc, or fmincon. Or GA or others from the global optimization toolbox, if you have that toolbox.
Or, if you have the functions in symbolic form, you can always solve for the points where the gradient of the functions is zero, and then identify if that point is a local minimum, a maximum, or just a saddle point.
What do you do with a vector? Just use the function min. If you want to somehow find where a min lies BETWEEN points, then you will need to use some interpolant, then computing the minimum point of the interpolant on that set of points. But this is no better than the interpolation method you will use.

More Answers (1)

Torsten
Torsten on 15 Jul 2023
In the case above, your objective function is separable in the optimization variables. Thus you can solve two independent problems using "fminbnd" and multiply the results.
For more difficult cases, use "fmincon".
  2 Comments
John D'Errico
John D'Errico on 15 Jul 2023
Be careful about the assumption that the minimum of the product of two functions, solved independently is the global minimum.
Consider the function
syms x y
Fx = (x^2 - 1);
Fy = (y^2 + 4*y - 4);
fplot(Fx)
hold on
fplot(Fy)
hold off
grid on
And, clearly, Fx has a minimum at x==0, and Fy has a minimum at y==-2.
solve(diff(Fx) == 0)
ans = 
0
solve(diff(Fy) == 0)
ans = 
However, is the product of those two functions a minimum at the point (0,-2)? No. In fact, that point is a local MAXIMUM, and the product of the two functions is unbounded from below.
Fxy = Fx*Fy;
fsurf(Fxy,[-3,3 -3,3])
Torsten
Torsten on 15 Jul 2023
I assumed the function to be separable (as in the case given):
F(x,y) = f1(x) * f2(y)
I forgot to add that f1,f2 should be >=0, but this is also true for the example given.

Sign in to comment.

Categories

Find more on Optimization in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!