Supplied objective function must return a scalar value in fmincon

1 次查看(过去 30 天)
Hey guys please help me I am getting this error in my optimization problem
Below is the Data File
global SL V p r k m n C Z s
SL = 0.75;
V = 94100;
p = [0.07,0.18,0.2,0.3];
r = [55,47,45,49];
k = [33,28,29,30];
m = 4;
n= 4;
C = [78,69,70,73;
64,68,56,59;
34,39,42,41;
52,47,48,45];
Z =[250 250 250 250;
320 320 320 320;
440 440 440 440;
350 350 350 350];
s = [110,95,99,100;
110,95,99,100;
110,95,99,100;
110,95,99,100];
bguess = randi(4,4);
bguess = (bguess<2);
Q0 = [zeros(4,4) bguess];
% call the solver
xopt = fmincon(@EP, Q0,[],[],[],[],[],[]);
Below is the Objective Function File
function G = EP(Q,b)
global s r k C m n
rng;
y = rand(4);
b = randi(4,4);
b = (b<2);
q = 0;
for i = 1:m
for j = 1:n
q = q + y(i,j)*Q(i,j);
end
end
x = sym('x',[1,4]); %x as symbolic variable
f1 = 0;
for i = 1:m
for j = i:n
f1 = f1 + s(i,j)*b(i,j)*x(j);
end
end
f2 = 0;
for i = 1:m
for j = 1:n
f2 = f2+C(i,j)*b(i,j)*y(i,j)*Q(i,j);
end
end
f3 = 0;
f3a = 0;
for i = 1:m
for j = 1:n
f3a = f3a + y(i,j)*Q(i,j)-x(j);
end
end
for i = 1:m
for j = 1:n
f3 = f3 + b(i,j)*r(j)*f3a;
end
end
f4 = 0;
for i = 1:m
for j = 1:n
f4 = f4+ s(j)*b(i,j)*y(i,j)*Q(i,j);
end
end
f5 = 0;
f5a = 0;
for i = 1:m
for j = 1:n
f5a = f5a + x(j) -y(i,j)*Q(i,j);
end
end
for i = 1:m
for j = 1:n
f5 = f5 + b(i,j)*k(j)*f5a;
end
end
F1 = int(((f1 - f2 + f3).*normpdf(x, 400, 100)),0,q);
F2 = int(((f4 - f2 - f5).*normpdf(x, 400, 100)),q,Inf);
G = -(F1 +F2);
end
This is the error I am getting. Please help me.
  9 个评论
Walter Roberson
Walter Roberson 2020-7-23
"(reminder to myself)" indicates that I need to return to this question and give you a reply when I have more time. I have been working on so many questions recently that the ones I still need to do more work on, are scrolling off the first three pages of the lists of my activity.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by