Error using function. I get the error Array indices must be positive integers or logical values.
Show older comments
clear all
clc
format short
lambda = 0.9;
ES = zeros(5);
SCV = ES; %initializing SCV
TH = ES; %initializing TH
EW = ES; %initializing EW
% a = 1:5;
% b = a;
% nodes = create_nodes(a, b);
for i=1:5
for j=1:5
ES(i,j) = 5-abs(i-3)-abs(j-3); %compute service time
SCV(i,j) = abs((i-3)*(j-3)); %compute scv
end
end
EW(1,1) = ES(1,1)*(1+0.5*(1+SCV(1,1))*0.9*1*ES(1,1)/(1-0.9*1*ES(1,1)));
V(1,1) = 1;
V(1,2) = 0.5;
EW(1,2) = ES(1,2)*(1+0.5*(1+SCV(1,2))*0.9*V(1,2)*ES(1,2)/(1-0.9*V(1,2)*ES(1,2)));
x(4) = 0.5;
x(7) = 0.5;
x(9) = 0.5;
V_init = 0.5;
for i = 3:5 % compute sojourn time for row 1
V_fun{i} = @(x) V_init*x(i-2);
EW_fun{i} = @(x) ES(1,i)*(1+0.5*(1+SCV(1,i))*0.9*V_fun{i}*ES(1,i)/(1-0.9*V_fun{i}*ES(1,i)));
V_init = @(x) V_fun{i};
fun{i} = @(x) V_fun{i}*EW_fun{i};
end
V_init = 1;
for j = 6:8 % compute sojourn time for row 2
V_fun{j} = @(x) 0.5*(1-x(1))*V_init*x(j-2);
EW_fun{j} = @(x) ES(2,j-3)*(1+0.5*(1+SCV(2,j-3))*0.9*V_fun{j}*ES(2,j-3)/(1-0.9*V_fun{j}*ES(2,j-3)));
V_init = @(x) V_fun(j);
% fun{j} = @(x) V_fun(j)*EW_fun{j};
end
V_init = 0.5*x(1)*(1-x(2))*(1-x(5));
for i = 9:10 % compute sojourn time for row 3
V_fun{i} = @(x) V_init*x(i-2);
EW_fun{i} = @(x) ES(3,i-5)*(1+0.5*(1+SCV(1,i-5))*0.9*V_fun{i}*ES(1,i-5)/(1-0.9*V_fun{i}*ES(1,i-5)));
V_init = @(x) V_fun{i};
% fun{i} = @(x) V_fun{i}*EW_fun{i};
end
V_fun{11} = @(x) 0.5*x(1)*x(2)*(1-x(3))*(1-x(6))*(1-x(8))*x(9);
EW_fun{11} = @(x) ES(4,5)*(1+0.5*(1+SCV(4,5))*0.9*V_fun{11}*ES(4,5)/(1-0.9*V_fun{11}*ES(4,5)));
% fun{11} = @(x) V_fun{11}*EW_fun{11};
V_fun{12} = @(x) 0.5*x(1)*x(2)*x(3)*x(10);
EW_fun{12} = @(x) ES(5,5)*(1+0.5*(1+SCV(5,5))*0.9*V_fun{12}*ES(5,5)/(1-0.9*V_fun{12}*ES(5,5)));
% fun{12} = @(x) V_fun{12}*EW_fun{12};
% funMin = @(x) sum([fun{:}])
V_fun{1} = V(1,1);
V_fun{2} = V(1,2);
EW_fun{1} = EW(1,1);
EW_fun{2} = EW(1,2);
% fun{1} = @(x) V_fun{1}*EW_fun{1};
% fun{2} = @(x) V_fun{2}*EW_fun{2}
fun = @(x) cellfun(@(g,h)(g(x)*(h(x))),V_fun,EW_fun);
funMin = @(x) sum([fun{:}]);
x0 = zeros(1,10);
Aeq = [];
beq = [];
lb = zeros(1,10);
ub = ones(1,10);
x = fmincon(fun,x0,[],[],Aeq,beq,lb,ub);
Accepted Answer
More Answers (0)
Categories
Find more on Descriptive Statistics and Visualization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!