Find minimum of multi-variable function on fixed interval with additional parameter inputs
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Tom Leblicq
am 17 Mär. 2021
Beantwortet: Alan Weiss
am 18 Mär. 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)
funfcn = optimfcnchk(FUN,'fmincon',length(varargin),funValCheck,flags.grad,flags.hess,false,Algorithm);
Error in Untitled2 (line 51)
[x, fval] = fmincon(f(x,xin2), [rand(), rand(), rand()], A, b, Aeq, Beq, lb, ub)
Can someone help me?
Kind regadrs,
Tom
0 Kommentare
Akzeptierte Antwort
Alan Weiss
am 18 Mär. 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
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Linear Algebra finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!