# Find minimum of multi-variable function on fixed interval with additional parameter inputs

14 views (last 30 days)
Tom Leblicq on 17 Mar 2021
Answered: Alan Weiss on 18 Mar 2021
Hello all,
I would like to find the minimum of a family of functions on a fixed interval.
function yx = test_function(x,xin2)
a=xin2(1);
b=xin2(2);
c=xin2(3);
yx = abs((x(1)*x(2))/4 + ((x(1)^2*x(2)^2)/a + (x(1)*x(2))/b - 1/4)^(c) + 1/2)+x(3);
Thus, I would like to find the minimum of yx (which is determined by x(1), x(2) and x(3)) for a given set of values for a,b,c.
As I would like to repeat this exercise for a large number of combinations of a,b,c I would like to be able to change these automatically in a loop.
xin2=[16,4,1/2];
lb = [0 0 0];
ub = [1 1 1];
f=@test_function;
[x, fval] = fmincon(f(x,xin2), [rand(), rand(), rand()], A, b, Aeq, Beq, lb, ub)
The error message I get:
Error using optimfcnchk (line 101)
FUN must be a function, a valid character vector expression, or an inline function object.
Error in fmincon (line 415)
Error in Untitled2 (line 51)
[x, fval] = fmincon(f(x,xin2), [rand(), rand(), rand()], A, b, Aeq, Beq, lb, ub)
Can someone help me?
Tom

Alan Weiss on 18 Mar 2021
You need to pass the parameters correctly. See Passing Extra Parameters. In your case, you need to either nest the function in a function that changes the parameters, or recreate an anonymous function each time, something like
xin = [16 4 1/2];
f = @(x)test_function(x,xin);
[x, fval] = fmincon(f, rand(1,3), A, b, Aeq, Beq, lb, ub)
Alan Weiss
MATLAB mathematical toolbox documentation