Supplied objective function must return a scalar value
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
EDOARDO GELMI
am 8 Jan. 2024
Kommentiert: Star Strider
am 8 Jan. 2024
I have to minimize a function with FMINCON:
f = @(x,y) k*x.*(teta_in-y)
i create this script to apply fmincon:
x0 = [2000,10];
A = [1 0;0 -1];
b = [25;2273];
f = cell(2,1)
f{1} = @(x) k*x.*(teta_in-y)
f{2} = @(x) k*x.*(teta_in-y)
[xmin,fval] =fmincon(f,x0,A,b)
But the programme give me the error: Supplied objective function must return a scalar value
If you have a different way to minimize that function with fmincon i appreciate that
2 Kommentare
Dyuman Joshi
am 8 Jan. 2024
Bearbeitet: Dyuman Joshi
am 8 Jan. 2024
What are the values of k and teta_in?
Why do you use the same function twice?
Also, share the mathematical definition of the objective function you have to minimize.
Akzeptierte Antwort
Star Strider
am 8 Jan. 2024
The function needs to return one parameter vector. One way to do that is to create a second function to map the inpouts to to such a vector:
ffcn = @(b)f(b(1),b(2));
Then, providing random values for the missing constants ‘k’ and ‘teta_in’ and running it produces —
k = rand
teta_in = rand
f = @(x,y) k*x.*(teta_in-y);
ffcn = @(b)f(b(1),b(2));
x0 = [2000,10];
A = [1 0;0 -1];
b = [25;2273];
[xmin,fval] =fmincon(ffcn,x0,A,b)
.
11 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical 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!