Error happen when doing optimization by using "surrogateopt"
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
HUNG JUI CHIU
am 22 Apr. 2021
Beantwortet: Stephan
am 22 Apr. 2021
I am trying to do optimization by using "surrogateopt" function.
I got an error "Objective function must return a scalar value".
And I couldn't find the problem.
clear
close all
clc
h = 0.01;
t = 0:h:10;
x = [0 0]';
for i = 1:1001
x1(i) = x(1);
x2(i) = x(2);
if x1(i) >0
a = pi/3;
elseif x1(i)<=0
a = -pi/3;
end
A = [cos(a) sin(a);
sin(a) cos(a)];
B = [0 1]';
intcon = 1;
lb = -1;
ub = 1;
obj =@(u) fun(A, x, B, u);
u = surrogateopt(obj, lb, ub, intcon);
x = fun(A, x, B, u);
end
figure
plot(x1, x2)
grid on
function f1 = fun(A, x, B, u)
f1 = 0.8*A*x+B*u;
end
0 Kommentare
Akzeptierte Antwort
Stephan
am 22 Apr. 2021
f1 is a 2x1 vector - the objective of an optimization has to be a scalar. Thats the error. You need a criterion that expresses the success of your optimization as a scalar.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Surrogate Optimization 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!