You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Writing equations in a matrix form
5 views (last 30 days)
Show older comments
Hi MATLAB experts,
Could any one please help me to write-down the following equations into a matrix form? the initial value of c = zeros(I, L, K, M)
0<= c(i, j, k, m) <= 1 for all k= {1, 2, ...., K} and m = {1, 2, ..., M} and i = {1,...., I} and j = {1,..., L}
0<=sum_{j} sum_{i} c(i,j,k,m) <= 1 for all k= {1, 2, ...., K} and m = {1, 2, ..., M}
4 Comments
Walter Roberson
on 19 Apr 2019
The first set of conditions you would normally express through lb / ub matrices, unless you were using Problem Based Optimization.
Susan
on 19 Apr 2019
Edited: Susan
on 19 Apr 2019
Thanks for your reply.
Do you mean I will have
lb = zeros(I,L, K, M) and ub = ones(I,L, K, M)
for the first set of conditions?
Can I write the second set of conditions as follows
sum(sum(c(:,:,:,:))) - 1 <= 0
nonlcon=@(c) deal([],sum(sum(c(:,:,:,:))) -1);
Is it correct? Is this constraint a linear or nonlinear?
Walter Roberson
on 19 Apr 2019
Edited: Walter Roberson
on 19 Apr 2019
Yes, those should be okay lb and ub.
Which release are you using? Which optimizer are you using?
Your task might be easier to express with Problem Based Optimization.
Do not use nonlinear constraints for those sum constraints: you only need linear constraints for those. It is just a nuisance to write out the matrices.
Susan
on 19 Apr 2019
Thanks for your reply.
I am using R2016b and trying to use fmincom.
I am not familiar with Problem Based Optimization. But I will take a look to see how I can use that.
Do you know how I should write the second constraint? Thanks
sum(sum(c(:, :, k,m))) <= 1 for all k and m.
Accepted Answer
Walter Roberson
on 19 Apr 2019
For any one particular scalar k and scalar m, you can express sum_{j} sum_{i} c(i,j,k,m) in range 0 to 1 as a linear constraint. The portion relevant to that k and m would be in the A matrix like
A(something,:) = [zeros(1, SOMETHING), ones(1, I*J), zeros(1,SOMETHINGELSE)];
b(something) = 1;
A(something+1,:) = [zeros(1, SOMETHING), -ones(1,I*J), zeros(1,SOMETHINGELSE)];
b(something) = 0;
You would have to walk this through K by M iterations, increasing the value of SOMETHING by I*J each time, and decreasing the value of SOMETHINGELSE by the same value.
An easier way of generating this would be something like:
blk = repmat({[ones(1, I*J); -ones(1, I*J)]}, 1, K*M);
A = blkdiag(blk{:});
b = zeros(size(A,1));
b(1:2:end) = 1;
21 Comments
Walter Roberson
on 20 Apr 2019
x=c(:);
A*x<=b
Susan
on 22 Apr 2019
Edited: Susan
on 22 Apr 2019
I have got another question. Your reply would be greatly appreciated.
I define the objective function as follows
syms c
f{i, j, k, m} = ps(j, k)*c(i, j, k, m)*B(k,m)*log2(1 + (Ass(i, j, k, m)*SINR{i, j, k, m})/(ps(j, k)*c(i, j, k, m)*B(k,m))); (for all i, j, k, m)
and I have got the following errors:
Error using sub2ind (line 43)
Out of range subscript.
Error in sym/subsref (line 809)
R_tilde = sub2ind(size(L), Idx.subs{:});
The objective function works fine for c0 but I don't get the issue when I have "syms c". Any idea?
Thanks in advance
Susan
on 22 Apr 2019
Edited: Susan
on 22 Apr 2019
I guess I found the issue. I defind the c as a matrix and it works. Do you think it was the issue or there is something else that I am not aware of ? Thanks.
BTW, I define the objfun as
objfun = @(c) f(c)
but I get the following error in the line that I called objfun i.e.,
[x,fval]=fmincon('objfun',c0,A,b,[],[],lb,ub);
Undefined function or variable 'objfun'.
Error in fmincon (line 536)
initVals.f = feval(funfcn{3},X,varargin{:});
Any idea?
Walter Roberson
on 22 Apr 2019
Do not use a quoted string for the first argument of fmincon. Always pass it a function handle instead.
(By the time you know enough MATLAB to know when this rule can be safely violated, you will not want to violate it and will dislike that you have to violate it.)
[x, fval] = fmincon(@f, c0, A, b, [], [], lb, ub)
Susan
on 22 Apr 2019
Edited: Susan
on 22 Apr 2019
Thanks for your reply.
I am lost.
If I call [x, fval] = fmincon(@f, c0, A, b, [], [], lb, ub) I got the following error:
Not enough input arguments.
Error in CalculateLAASumRate (line 29)
for k = 1 : numel(nbrOfSubCarriers)
Error in fmincon (line 536)
initVals.f = feval(funfcn{3},X,varargin{:});
Error in test_Lagrangian (line 217)
c=fmincon(@f,c0,A,b,[],[],lb,ub);
Caused by:
Failure in initial objective function evaluation. FMINCON cannot continue.
And when I try
objfun = @(c) f(c) %==> objfun is a function_handle
[x, fval] = fmincon(objfun, c0, A, b, [], [], lb, ub)
I get
Error using fmincon (line 684)
FMINCON requires all values returned by functions to be of data type double.
Error in test_Lagrangian (line 217)
c=fmincon(objfun,c0,A,b,[],[],lb,ub);
Walter Roberson
on 22 Apr 2019
I am lost as to what your f is. Above you defined syms c and the appear to assign to a particular cell array location in f based on indexing c, which was going to fail because syms c defines a scalar symbol and indexing a scalar symbol anywhere other than offset 1 will fail. But then you defined c as a matrix. Okay, but what is the definition of f now?
Susan
on 22 Apr 2019
Thanks for your reply.
This is what I am doing:
c = sym('c', [I J K M]);
for k = 1 : K
for m = 1 : M
for j = 1 : J
for i = 1 : I
f{i, j, k, m} = ps(j, k)*c(i, j, k, m)*B(k,m)*log2(1 + (Ass(i, j, k, m)*SINR{i, j, k, m})/(ps(j, k)*c(i, j, k, m)*B(k,m)));
end
end
end
end
function[sumr] = Calculatesumr(I, M, K, J, tr_prob, Ta, Pf, f, NumUEPerOperator)
sumra = 0;
for k = 1 : K
for m = 1 : M
for j = 1 : J
for i = 1 : I
sumra = sumra + ((1 - tr_prob(k))*(1 - Pf(k))*f{i + NumUEPerOperator*(j - 1), j, k, m} )/Ta(k);
end
end
end
end
sumr = sumra;
end
objfun = @(c) Calculatesumr(I, M, K, J, tr_prob, Ta, Pf, f, NumUEPerOperator)
Walter Roberson
on 22 Apr 2019
At the moment it is not obvious to me why you are using a cell array for f, instead of a sym array of size I J K M, such as
f = zeros(I, J, K, M, 'sym');
Your f is defined in terms of the symbolic array c, so your result of Calculatesumr() is going to be in terms of the variables in the symbolic array c because it involves f and f is defined in terms of the symbolic array c.
You define objfun in terms of a dummy numeric parameter c that will be ignored, and then Calculatesumr() will be called, returning an expression in terms of the symbolic variables c3_2_5_4, c2_1_4_3, and so on (what was in the symbolic array c.) fmincon() will then complain because the result is not numeric.
When you define a parameter named c to a function, and the function involves symbolic variables that were originally stored in a variable named c, then there is no connection made between the parameter and the symbolic variables -- not unless you deliberately subs() the parameters in.
What you should probably be doing is using matlabFunction() with the 'vars' parameter to convert the symbolic expression resulting from Calculatesumr into an anonymous function (taking numeric inputs) that can be called by fmincon()
Susan
on 22 Apr 2019
Edited: Susan
on 23 Apr 2019
Thanks again Walter for your detailed explanation.
I am using cell array for f because I have
for k = 1 : K
for m = 1 : M(k) %% size(M) = 1*K
for j = 1 : J
for i = 1 : I(j) %% size(I) = 1* J
f = ....
end
end
end
end
I don't know if in this case I can use sym array insted of cell array. Can I?
Regarding the fmincon function, I get to take the following steps, right?
ht = matlabFunction(Calculatesumr , 'Vars', c)
[x, fval] = fmincon(@ht, c0, A, b, [], [], lb, ub)
I am not sure about the 'Vars' parameter though. Please put me right if I am wrong. Thank you very much.
Susan
on 23 Apr 2019
Edited: Susan
on 23 Apr 2019
Could you please tell me whether I am using the matlabFunction() and fmincon() correctly or not? Thanks
objfun_symbExpression = Calculatesumr(I, M, K, J, tr_prob, Ta, Pf, f, NumUEPerOperator);
objfun_anonymousfunction = matlabFunction(objfun_symbExpression, 'Vars', c);
objfun = @( c ) objfun_anonymousfunction(c);
[x,fval]=fmincon(objfun,c0,A,b,[],[],lb,ub);
I am getting the following error
Not enough input arguments.
Error in
symengine>@(c1_1_1_1,c2_1_1_1,c3_1_1_1,c1_2_1_1,c2_2_1_1,c3_2_1_1,c1_3_1_1,c2_3_1_1,c3_3_1_1,c1_1_2_1,c2_1_2_1,c3_1_2_1,c1_2_2_1,c2_2_2_1,c3_2_2_1,c1_3_2_1,c2_3_2_1,c3_3_2_1,c1_1_3_1,c2_1_3_1,c3_1_3_1,c1_2_3_1,c2_2_3_1,c3_2_3_1,c1_3_3_1,c2_3_3_1,c3_3_3_1,c1_1_4_1,c2_1_4_1,c3_1_4_1,c1_2_4_1,c2_2_4_1,c3_2_4_1,c1_3_4_1,c2_3_4_1,c3_3_4_1,c1_1_5_1,c2_1_5_1,c3_1_5_1,c1_2_5_1,c2_2_5_1,c3_2_5_1,c1_3_5_1,c2_3_5_1,c3_3_5_1,c1_1_6_1,c2_1_6_1,c3_1_6_1,c1_2_6_1,c2_2_6_1,c3_2_6_1,c1_3_6_1,c2_3_6_1,c3_3_6_1,c1_1_7_1,c2_1_7_1,c3_1_7_1,c1_2_7_1,c2_2_7_1,c3_2_7_1,c1_3_7_1,c2_3_7_1,c3_3_7_1,c1_1_8_1,c2_1_8_1,c3_1_8_1,c1_2_8_1,c2_2_8_1,c3_2_8_1,c1_3_8_1,c2_3_8_1,c3_3_8_1,c1_1_9_1,c2_1_9_1,c3_1_9_1,c1_2_9_1,c2_2_9_1,c3_2_9_1,c1_3_9_1,c2_3_9_1,c3_3_9_1,c1_1_10_1,c2_1_10_1,c3_1_10_1,c1_2_10_1,c2_2_10_1,c3_2_10_1,c1_3_10_1,c2_3_10_1,c3_3_10_1,c1_1_1_2,c2_1_1_2,c3_1_1_2,c1_2_1_2,c2_2_1_2,c3_2_1_2,c1_3_1_2,c2_3_1_2,c3_3_1_2,c1_1_2_2,c2_1_2_2,c3_1_2_2,c1_2_2_2,c2_2_2_2,c3_2_2_2,c1_3_2_2,c2_3_2_2,c3_3_2_2,c1_1_3_2,c2_1_3_2,c3_1_3_2,c1_2_3_2,c2_2_3_2,c3_2_3_2,c1_3_3_2,c2_3_3_2,c3_3_3_2,c1_1_4_2,c2_1_4_2,c3_1_4_2,c1_2_4_2,c2_2_4_2,c3_2_4_2,c1_3_4_2,c2_3_4_2,c3_3_4_2,c1_1_5_2,c2_1_5_2,c3_1_5_2,c1_2_5_2,c2_2_5_2,c3_2_5_2,c1_3_5_2,c2_3_5_2,c3_3_5_2,c1_1_6_2,c2_1_6_2,c3_1_6_2,c1_2_6_2,c2_2_6_2,c3_2_6_2,c1_3_6_2,c2_3_6_2,c3_3_6_2,c1_1_7_2,c2_1_7_2,c3_1_7_2,c1_2_7_2,c2_2_7_2,c3_2_7_2,c1_3_7_2,c2_3_7_2,c3_3_7_2,c1_1_8_2,c2_1_8_2,c3_1_8_2,c1_2_8_2,c2_2_8_2,c3_2_8_2,c1_3_8_2,c2_3_8_2,c3_3_8_2,c1_1_9_2,c2_1_9_2,c3_1_9_2,c1_2_9_2,c2_2_9_2,c3_2_9_2,c1_3_9_2,c2_3_9_2,c3_3_9_2,c1_1_10_2,c2_1_10_2,c3_1_10_2,c1_2_10_2,c2_2_10_2,c3_2_10_2,c1_3_10_2,c2_3_10_2,c3_3_10_2)(c2_1_3_2.*log(4.661334020125402e-5./c2_1_3_2+1.0).*2.700000000000003)./log(2.0)+(c1_2_9_2.*log(1.213086237114686e-4./c1_2_9_2+1.0).*2.700000000000003)./log(2.0)+(c2_2_3_1.*log(1.973717331697037e-4./c2_2_3_1+1.0).*6.27e1)./log(2.0)+(c2_1_2_1.*log(2.384204117902418e-4./c2_1_2_1+1.0).*2.700000000000003)./log(2.0)+(c2_2_8_1.*log(2.04206324308796e-5./c2_2_8_1+1.0).*6.27e1)./log(2.0)+(c2_2_4_2.*log(5.729097402850286e-4./c2_2_4_2+1.0).*6.27e1)./log(2.0)+(c3_3_2_2.*log(5.557877214371519e-5./c3_3_2_2+1.0).*2.700000000000003)./log(2.0)+(c2_3_2_1.*log(4.37974363291977e-5./c2_3_2_1+1.0).*6.27e1)./log(2.0)+(c3_2_5_2.*log(7.522069025134307e-4./c3_2_5_2+1.0).*6.27e1)./log(2.0)+(c2_3_8_2.*log(3.200131464345081e-4./c2_3_8_2+1.0).*2.700000000000003)./log(2.0)+(c1_3_2_2.*log(3.969794324835312e-5./c1_3_2_2+1.0).*6.27e1)./log(2.0)+(c3_2_1_2.*log(4.595366595148829e-4./c3_2_1_2+1.0).*6.27e1)./log(2.0)+(c2_1_7_2.*log(4.729830018171281e-5./c2_1_7_2+1.0).*2.700000000000003)./log(2.0)+(c2_3_4_2.*log(3.553923526702777e-4./c2_3_4_2+1.0).*2.700000000000003)./log(2.0)+(c3_3_4_2.*log(6.73672598667724e-5./c3_3_4_2+1.0).*2.700000000000003)./log(2.0)+(c3_3_4_2.*log(6.736725986695873e-5./c3_3_4_2+1.0).*6.27e1)./log(2.0)+(c2_1_6_2.*log(3.175894054653654e-5./c2_1_6_2+1.0).*2.700000000000003)./log(2.0)+(c3_1_7_2.*log(5.594025491556619e-5./c3_1_7_2+1.0).*2.700000000000003)./log(2.0)+(c3_2_8_1.*log(1.958377898353446e-4./c3_2_8_1+1.0).*6.27e1)./log(2.0)+(c2_2_3_1.*log(1.97370972985957e-4./c2_2_3_1+1.0).*2.700000000000003)./log(2.0)+(c2_1_8_1.*log(9.076779160220973e-5./c2_1_8_1+1.0).*6.27e1)./log(2.0)+(c1_3_9_2.*log(2.008761598043622e-5./c1_3_9_2+1.0).*2.700000000000003)./log(2.0)+(c1_3_6_1.*log(5.912517056203199e-5./c1_3_6_1+1.0).*6.27e1)./log(2.0)+(c2_1_1_1.*log(4.469878063836057e-5./c2_1_1_1+1.0).*6.27e1)./log(2.0)+(c3_2_9_2.*log(4.984847383089513e-6./c3_2_9_2+1.0).*2.700000000000003)./log(2.0)+(c2_2_9_2.*log(8.485904363436042e-4./c2_2_9_2+1.0).*2.700000000000003)./log(2.0)+(c2_3_4_2.*log(3.553923531715167e-4./c2_3_4_2+1.0).*6.27e1)./log(2.0)+(c3_1_3_1.*log(5.688006180694598e-4./c3_1_3_1+1.0).*2.700000000000003)./log(2.0)+(c3_2_9_2.*log(4.984849236683792e-6./c3_2_9_2+1.0).*6.27e1)./log(2.0)+(c3_3_6_1.*log(1.456764732041037e-4./c3_3_6_1+1.0).*2.700000000000003)./log(2.0)+(c2_2_6_2.*log(1.698824113637671e-4./c2_2_6_2+1.0).*2.700000000000003)./log(2.0)+(c1_1_6_1.*log(1.428026935615791e-4./c1_1_6_1+1.0).*6.27e1)./log(2.0)+(c1_2_10_1.*log(4.461843721426979e-5./c1_2_10_1+1.0).*6.27e1)./log(2.0)+(c1_2_9_1.*log(2.482724973331773e-4./c1_2_9_1+1.0).*6.27e1)./log(2.0)+(c3_1_2_1.*log(3.472779552279211e-5./c3_1_2_1+1.0).*2.700000000000003)./log(2.0)+(c3_2_7_1.*log(9.256119773541176e-6./c3_2_7_1+1.0).*6.27e1)./log(2.0)+(c1_2_9_1.*log(2.482724155699465e-4./c1_2_9_1+1.0).*2.700000000000003)./log(2.0)+(c3_3_2_2.*log(5.557877214512173e-5./c3_3_2_2+1.0).*6.27e1)./log(2.0)+(c3_1_4_2.*log(1.53543091944615e-4./c3_1_4_2+1.0).*2.700000000000003)./log(2.0)+(c1_1_5_2.*log(1.319447995648612e-4./c1_1_5_2+1.0).*2.700000000000003)./log(2.0)+(c2_3_1_1.*log(1.357167375932804e-5./c2_3_1_1+1.0).*6.27e1)./log(2.0)+(c2_1_9_2.*log(9.440168614601304e-5./c2_1_9_2+1.0).*2.700000000000003)./log(2.0)+(c2_2_5_2.*log(8.432664626625371e-6./c2_2_5_2+1.0).*6.27e1)./log(2.0)+(c1_2_4_2.*log(7.110336694826498e-5./c1_2_4_2+1.0).*2.700000000000003)./log(2.0)+(c3_1_8_1.*log(8.096486953587943e-5./c3_1_8_1+1.0).*2.700000000000003)./log(2.0)+(c1_3_7_1.*log(1.405180023044887e-4./c1_3_7_1+1.0).*6.27e1)./log(2.0)+(c2_1_9_2.*log(9.440174332522934e-5./c2_1_9_2+1.0).*6.27e1)./log(2.0)+(c1_1_7_2.*log(8.569384644204782e-4./c1_1_7_2+1.0).*2.700000000000003)./log(2.0)+(c2_3_2_2.*log(1.000426840357526e-3./c2_3_2_2+1.0).*2.700000000000003)./log(2.0)+(c1_3_6_1.*log(5.912516691563455e-5./c1_3_6_1+1.0).*2.700000000000003)./log(2.0)+(c1_3_4_2.*log(1.538394094554665e-4./c1_3_4_2+1.0).*2.700000000000003)./log(2.0)+(c1_3_8_2.*log(5.921927196211666e-5./c1_3_8_2+1.0).*2.700000000000003)./log(2.0)+(c3_2_8_2.*log(4.025084801366024e-6./c3_2_8_2+1.0).*6.27e1)./log(2.0)+(c2_3_5_1.*log(1.663444628439551e-5./c2_3_5_1+1.0).*2.700000000000003)./log(2.0)+(c1_3_6_2.*log(1.293081749362346e-5./c1_3_6_2+1.0).*2.700000000000003)./log(2.0)+(c3_3_8_1.*log(2.150928013852878e-4./c3_3_8_1+1.0).*6.27e1)./log(2.0)+(c1_2_4_1.*log(1.913709359525297e-4./c1_2_4_1+1.0).*2.700000000000003)./log(2.0)+(c3_1_1_1.*log(4.940630101675829e-4./c3_1_1_1+1.0).*6.27e1)./log(2.0)+(c3_3_3_2.*log(2.284558083424065e-4./c3_3_3_2+1.0).*2.700000000000003)./log(2.0)+(c1_2_10_1.*log(4.461843621269375e-5./c1_2_10_1+1.0).*2.700000000000003)./log(2.0)+(c2_1_7_1.*log(1.113855958188974e-3./c2_1_7_1+1.0).*6.27e1)./log(2.0)+(c1_1_9_1.*log(1.01374617819942e-4./c1_1_9_1+1.0).*2.700000000000003)./log(2.0)+(c3_3_5_2.*log(2.611169342698065e-4./c3_3_5_2+1.0).*2.700000000000003)./log(2.0)+(c3_2_6_1.*log(3.679956897528039e-5./c3_2_6_1+1.0).*6.27e1)./log(2.0)+(c2_1_6_1.*log(9.392761080009399e-5./c2_1_6_1+1.0).*6.27e1)./log(2.0)+(c1_3_4_2.*log(1.538394147938948e-4./c1_3_4_2+1.0).*6.27e1)./log(2.0)+(c2_2_4_1.*log(4.9678277840158e-6./c2_2_4_1+1.0).*2.700000000000003)./log(2.0)+(c2_2_8_1.*log(2.042063040438785e-5./c2_2_8_1+1.0).*2.700000000000003)./log(2.0)+(c1_1_3_2.*log(1.232503168480349e-3./c1_1_3_2+1.0).*2.700000000000003)./log(2.0)+(c3_2_6_2.*log(3.608381738328319e-4./c3_2_6_2+1.0).*6.27e1)./log(2.0)+(c3_2_4_1.*log(5.449377668625627e-4./c3_2_4_1+1.0).*6.27e1)./log(2.0)+(c1_3_2_1.*log(5.187942724293274e-5./c1_3_2_1+1.0).*6.27e1)./log(2.0)+(c2_2_4_2.*log(5.729093566329847e-4./c2_2_4_2+1.0).*2.700000000000003)./log(2.0)+(c2_1_6_1.*log(9.392740737458586e-5./c2_1_6_1+1.0).*2.700000000000003)./log(2.0)+(c1_1_10_2.*log(1.354274790070846e-4./c1_1_10_2+1.0).*2.700000000000003)./log(2.0)+(c3_3_3_1.*log(1.275067422731125e-4./c3_3_3_1+1.0).*6.27e1)./log(2.0)+(c3_3_10_2.*log(7.675482745790704e-4./c3_3_10_2+1.0).*6.27e1)./log(2.0)+(c2_1_2_1.*log(2.384205964792891e-4./c2_1_2_1+1.0).*6.27e1)./log(2.0)+(c3_2_1_2.*log(4.595366095966422e-4./c3_2_1_2+1.0).*2.700000000000003)./log(2.0)+(c1_3_10_1.*log(6.740522878020518e-5./c1_3_10_1+1.0).*2.700000000000003)./log(2.0)+(c3_1_4_1.*log(1.38500161753365e-5./c3_1_4_1+1.0).*6.27e1)./log(2.0)+(c3_3_5_1.*log(1.829910896120699e-4./c3_3_5_1+1.0).*2.700000000000003)./log(2.0)+(c2_2_2_1.*log(7.558763967022339e-5./c2_2_2_1+1.0).*6.27e1)./log(2.0)+(c3_1_9_2.*log(9.967439060958481e-5./c3_1_9_2+1.0).*2.700000000000003)./log(2.0)+(c3_2_2_2.*log(1.228106886125817e-4./c3_2_2_2+1.0).*6.27e1)./log(2.0)+(c3_1_9_2.*log(9.967439090643528e-5./c3_1_9_2+1.0).*6.27e1)./log(2.0)+(c3_2_9_1.*log(1.648898267488357e-4./c3_2_9_1+1.0).*2.700000000000003)./log(2.0)+(c2_2_1_1.*log(1.692176363778982e-4./c2_2_1_1+1.0).*6.27e1)./log(2.0)+(c1_1_8_1.*log(4.780980190502675e-4./c1_1_8_1+1.0).*6.27e1)./log(2.0)+(c2_2_2_1.*log(7.558745437360602e-5./c2_2_2_1+1.0).*2.700000000000003)./log(2.0)+(c3_3_3_1.*log(1.275067422554162e-4./c3_3_3_1+1.0).*2.700000000000003)./log(2.0)+(c1_3_10_1.*log(6.740524271678065e-5./c1_3_10_1+1.0).*6.27e1)./log(2.0)+(c1_3_9_2.*log(2.008763326871702e-5./c1_3_9_2+1.0).*6.27e1)./log(2.0)+(c1_1_5_1.*log(1.537975575114146e-4./c1_1_5_1+1.0).*6.27e1)./log(2.0)+(c3_1_4_1.*log(1.385001615467321e-5./c3_1_4_1+1.0).*2.700000000000003)./log(2.0)+(c3_2_5_2.*log(7.522068922353348e-4./c3_2_5_2+1.0).*2.700000000000003)./log(2.0)+(c1_1_6_1.*log(1.42802488195388e-4./c1_1_6_1+1.0).*2.700000000000003)./log(2.0)+(c1_1_5_2.*log(1.319453892704594e-4./c1_1_5_2+1.0).*6.27e1)./log(2.0)+(c2_3_8_2.*log(3.200131466622681e-4./c2_3_8_2+1.0).*6.27e1)./log(2.0)+(c1_3_7_2.*log(2.120050041519761e-4./c1_3_7_2+1.0).*2.700000000000003)./log(2.0)+(c3_2_3_1.*log(4.834243388523898e-4./c3_2_3_1+1.0).*6.27e1)./log(2.0)+(c1_2_4_1.*log(1.913710149071611e-4./c1_2_4_1+1.0).*6.27e1)./log(2.0)+(c3_2_2_1.*log(6.325185963440156e-5./c3_2_2_1+1.0).*2.700000000000003)./log(2.0)+(c1_2_4_2.*log(7.1103380851198e-5./c1_2_4_2+1.0).*6.27e1)./log(2.0)+(c2_3_6_2.*log(4.126727905476189e-4./c2_3_6_2+1.0).*2.700000000000003)./log(2.0)+(c1_1_8_1.*log(4.780938150051171e-4./c1_1_8_1+1.0).*2.700000000000003)./log(2.0)+(c2_2_9_2.*log(8.4859160226389e-4./c2_2_9_2+1.0).*6.27e1)./log(2.0)+(c1_3_9_1.*log(1.935733550895296e-4./c1_3_9_1+1.0).*6.27e1)./log(2.0)+(c1_1_3_2.*log(1.232522570075739e-3./c1_1_3_2+1.0).*6.27e1)./log(2.0)+(c1_2_9_2.*log(1.213086598553184e-4./c1_2_9_2+1.0).*6.27e1)./log(2.0)+(c3_2_9_1.*log(1.648898281385053e-4./c3_2_9_1+1.0).*6.27e1)./log(2.0)+(c3_1_3_1.*log(5.688006185884601e-4./c3_1_3_1+1.0).*6.27e1)./log(2.0)+(c2_3_5_1.*log(1.663444646315982e-5./c2_3_5_1+1.0).*6.27e1)./log(2.0)+(c1_3_7_1.*log(1.405180013356742e-4./c1_3_7_1+1.0).*2.700000000000003)./log(2.0)+(c2_3_7_2.*log(7.581885797095326e-5./c2_3_7_2+1.0).*2.700000000000003)./log(2.0)+(c1_2_2_1.*log(6.343877445868848e-4./c1_2_2_1+1.0).*6.27e1)./log(2.0)+(c3_3_5_2.*log(2.611169351273466e-4./c3_3_5_2+1.0).*6.27e1)./log(2.0)+(c3_2_6_2.*log(3.608381680908266e-4./c3_2_6_2+1.0).*2.700000000000003)./log(2.0)+(c3_3_6_1.*log(1.456764732211091e-4./c3_3_6_1+1.0).*6.27e1)./log(2.0)+(c2_1_6_2.*log(3.176308680274093e-5./c2_1_6_2+1.0).*6.27e1)./log(2.0)+(c1_1_5_1.*log(1.537972120011483e-4./c1_1_5_1+1.0).*2.700000000000003)./log(2.0)+(c2_1_1_1.*log(4.469876539306762e-5./c2_1_1_1+1.0).*2.700000000000003)./log(2.0)+(c1_2_2_1.*log(6.343875024015616e-4./c1_2_2_1+1.0).*2.700000000000003)./log(2.0)+(c1_3_8_2.*log(5.921927406820357e-5./c1_3_8_2+1.0).*6.27e1)./log(2.0)+(c3_3_3_2.*log(2.284558084755119e-4./c3_3_3_2+1.0).*6.27e1)./log(2.0)+(c3_1_4_2.*log(1.535430942883223e-4./c3_1_4_2+1.0).*6.27e1)./log(2.0)+(c2_3_2_1.*log(4.379743614195532e-5./c2_3_2_1+1.0).*2.700000000000003)./log(2.0)+(c3_2_2_1.*log(6.325185997050446e-5./c3_2_2_1+1.0).*6.27e1)./log(2.0)+(c3_2_4_1.*log(5.44937712788617e-4./c3_2_4_1+1.0).*2.700000000000003)./log(2.0)+(c3_1_7_2.*log(5.594025513949421e-5./c3_1_7_2+1.0).*6.27e1)./log(2.0)+(c2_3_7_2.*log(7.581885818144822e-5./c2_3_7_2+1.0).*6.27e1)./log(2.0)+(c2_2_10_1.*log(3.219742241443294e-5./c2_2_10_1+1.0).*2.700000000000003)./log(2.0)+(c2_2_6_2.*log(1.698824573407164e-4./c2_2_6_2+1.0).*6.27e1)./log(2.0)+(c2_2_10_1.*log(3.219742266689613e-5./c2_2_10_1+1.0).*6.27e1)./log(2.0)+(c3_3_10_2.*log(7.675482739484303e-4./c3_3_10_2+1.0).*2.700000000000003)./log(2.0)+(c2_2_5_2.*log(8.432663232716602e-6./c2_2_5_2+1.0).*2.700000000000003)./log(2.0)+(c1_1_9_1.*log(1.013753693919345e-4./c1_1_9_1+1.0).*6.27e1)./log(2.0)+(c1_1_3_1.*log(1.276130161564401e-4./c1_1_3_1+1.0).*2.700000000000003)./log(2.0)+(c2_2_4_1.*log(4.96783374599404e-6./c2_2_4_1+1.0).*6.27e1)./log(2.0)+(c3_2_3_1.*log(4.834243294443376e-4./c3_2_3_1+1.0).*2.700000000000003)./log(2.0)+(c1_3_6_2.*log(1.293081766514975e-5./c1_3_6_2+1.0).*6.27e1)./log(2.0)+(c2_3_6_2.*log(4.126727964900137e-4./c2_3_6_2+1.0).*6.27e1)./log(2.0)+(c3_2_7_1.*log(9.2561196502388e-6./c3_2_7_1+1.0).*2.700000000000003)./log(2.0)+(c3_1_1_1.*log(4.940629619241917e-4./c3_1_1_1+1.0).*2.700000000000003)./log(2.0)+(c1_1_7_2.*log(8.569514955754829e-4./c1_1_7_2+1.0).*6.27e1)./log(2.0)+(c3_3_5_1.*log(1.829910896401041e-4./c3_3_5_1+1.0).*6.27e1)./log(2.0)+(c1_1_10_2.*log(1.354286503397928e-4./c1_1_10_2+1.0).*6.27e1)./log(2.0)+(c2_1_3_2.*log(4.661338283378261e-5./c2_1_3_2+1.0).*6.27e1)./log(2.0)+(c2_1_8_1.*log(9.076700315728709e-5./c2_1_8_1+1.0).*2.700000000000003)./log(2.0)+(c3_2_1_1.*log(1.141724959620909e-4./c3_2_1_1+1.0).*6.27e1)./log(2.0)+(c2_3_1_1.*log(1.357167373702702e-5./c2_3_1_1+1.0).*2.700000000000003)./log(2.0)+(c2_3_2_2.*log(1.000426875140687e-3./c2_3_2_2+1.0).*6.27e1)./log(2.0)+(c3_2_8_1.*log(1.958377893792828e-4./c3_2_8_1+1.0).*2.700000000000003)./log(2.0)+(c2_1_7_2.*log(4.729837054677384e-5./c2_1_7_2+1.0).*6.27e1)./log(2.0)+(c3_2_8_2.*log(4.025084653027512e-6./c3_2_8_2+1.0).*2.700000000000003)./log(2.0)+(c2_1_4_1.*log(9.725914801147167e-5./c2_1_4_1+1.0).*6.27e1)./log(2.0)+(c1_3_2_1.*log(5.187942328740618e-5./c1_3_2_1+1.0).*2.700000000000003)./log(2.0)+(c1_3_7_2.*log(2.120050489483678e-4./c1_3_7_2+1.0).*6.27e1)./log(2.0)+(c3_3_8_1.*log(2.150928013802931e-4./c3_3_8_1+1.0).*2.700000000000003)./log(2.0)+(c2_1_4_1.*log(9.725899883126643e-5./c2_1_4_1+1.0).*2.700000000000003)./log(2.0)+(c1_3_9_1.*log(1.935733343037886e-4./c1_3_9_1+1.0).*2.700000000000003)./log(2.0)+(c3_2_1_1.*log(1.141724952363403e-4./c3_2_1_1+1.0).*2.700000000000003)./log(2.0)+(c3_1_8_1.*log(8.096487120890757e-5./c3_1_8_1+1.0).*6.27e1)./log(2.0)+(c3_1_2_1.*log(3.47277955629085e-5./c3_1_2_1+1.0).*6.27e1)./log(2.0)+(c3_2_6_1.*log(3.679956878358732e-5./c3_2_6_1+1.0).*2.700000000000003)./log(2.0)+(c2_2_1_1.*log(1.692175519062596e-4./c2_2_1_1+1.0).*2.700000000000003)./log(2.0)+(c2_1_7_1.*log(1.113848483250759e-3./c2_1_7_1+1.0).*2.700000000000003)./log(2.0)+(c1_1_3_1.*log(1.276131398152123e-4./c1_1_3_1+1.0).*6.27e1)./log(2.0)+(c1_3_2_2.*log(3.969790510835165e-5./c1_3_2_2+1.0).*2.700000000000003)./log(2.0)+(c3_2_2_2.*log(1.228106876176335e-4./c3_2_2_2+1.0).*2.700000000000003)./log(2.0)
Error in fmincon (line 536)
initVals.f = feval(funfcn{3},X,varargin{:});
Error in test_Lagrangian (line 215)
[x,fval]=fmincon(objfun,c0,A,b,[],[],lb,ub);
Caused by:
Failure in initial objective function evaluation. FMINCON cannot continue.
Walter Roberson
on 23 Apr 2019
Use
'vars', {reshape(c,1,[])}
instead of
'vars', c
in matlabFunction
Susan
on 23 Apr 2019
Edited: Susan
on 23 Apr 2019
I got the following error now
Index exceeds matrix dimensions.
Error in
symengine>@(in1)(in1(:,78).*log(3.700708093693542e-4./in1(:,78)+1.0).*(-6.27e1))./log(2.0)-(in1(:,104).*log(4.669739411141582e-5./in1(:,104)+1.0).*6.27e1)./log(2.0)-(in1(:,51).*log(2.443358537890334e-4./in1(:,51)+1.0).*2.700000000000003)./log(2.0)-(in1(:,139).*log(2.514556287395105e-5./in1(:,139)+1.0).*2.700000000000003)./log(2.0)-(in1(:,139).*log(2.514556287930596e-5./in1(:,139)+1.0).*6.27e1)./log(2.0)-(in1(:,134).*log(2.570669932016933e-5./in1(:,134)+1.0).*2.700000000000003)./log(2.0)-(in1(:,117).*log(5.735376164543904e-5./in1(:,117)+1.0).*2.700000000000003)./log(2.0)-(in1(:,49).*log(1.867966529202098e-5./in1(:,49)+1.0).*2.700000000000003)./log(2.0)-(in1(:,22).*log(2.283723279140077e-5./in1(:,22)+1.0).*2.700000000000003)./log(2.0)-(in1(:,36).*log(4.870005093830326e-4./in1(:,36)+1.0).*6.27e1)./log(2.0)-(in1(:,168).*log(8.609158640878199e-5./in1(:,168)+1.0).*2.700000000000003)./log(2.0)-(in1(:,19).*log(4.298551229608035e-4./in1(:,19)+1.0).*2.700000000000003)./log(2.0)-(in1(:,18).*log(2.876034194067673e-4./in1(:,18)+1.0).*6.27e1)./log(2.0)-(in1(:,9).*log(7.764417568200059e-6./in1(:,9)+1.0).*2.700000000000003)./log(2.0)-(in1(:,148).*log(9.926594773194256e-6./in1(:,148)+1.0).*6.27e1)./log(2.0)-(in1(:,12).*log(1.582010745128305e-3./in1(:,12)+1.0).*6.27e1)./log(2.0)-(in1(:,28).*log(1.795141903330641e-4./in1(:,28)+1.0).*6.27e1)./log(2.0)-(in1(:,157).*log(1.285490118581143e-4./in1(:,157)+1.0).*2.700000000000003)./log(2.0)-(in1(:,61).*log(9.1145743322635e-4./in1(:,61)+1.0).*6.27e1)./log(2.0)-(in1(:,94).*log(4.455056376508116e-5./in1(:,94)+1.0).*2.700000000000003)./log(2.0)-(in1(:,71).*log(5.169490071789642e-5./in1(:,71)+1.0).*2.700000000000003)./log(2.0)-(in1(:,119).*log(6.720156612960165e-4./in1(:,119)+1.0).*2.700000000000003)./log(2.0)-(in1(:,12).*log(1.581969779598259e-3./in1(:,12)+1.0).*2.700000000000003)./log(2.0)-(in1(:,113).*log(5.320070826226837e-5./in1(:,113)+1.0).*2.700000000000003)./log(2.0)-(in1(:,113).*log(5.320070826369415e-5./in1(:,113)+1.0).*6.27e1)./log(2.0)-(in1(:,39).*log(7.712968431102731e-4./in1(:,39)+1.0).*2.700000000000003)./log(2.0)-(in1(:,14).*log(2.514300108820583e-5./in1(:,14)+1.0).*6.27e1)./log(2.0)-(in1(:,89).*log(2.149568195991095e-4./in1(:,89)+1.0).*6.27e1)./log(2.0)-(in1(:,151).*log(3.718849429834584e-5./in1(:,151)+1.0).*2.700000000000003)./log(2.0)-(in1(:,18).*log(2.876034182814147e-4./in1(:,18)+1.0).*2.700000000000003)./log(2.0)-(in1(:,134).*log(2.57066993398925e-5./in1(:,134)+1.0).*6.27e1)./log(2.0)-(in1(:,133).*log(5.617109026677226e-4./in1(:,133)+1.0).*6.27e1)./log(2.0)-(in1(:,32).*log(2.918025663930002e-5./in1(:,32)+1.0).*2.700000000000003)./log(2.0)-(in1(:,180).*log(2.489140391603624e-4./in1(:,180)+1.0).*6.27e1)./log(2.0)-(in1(:,48).*log(4.906767035366405e-5./in1(:,48)+1.0).*6.27e1)./log(2.0)-(in1(:,96).*log(7.394538106764381e-4./in1(:,96)+1.0).*6.27e1)./log(2.0)-(in1(:,9).*log(7.764417606133432e-6./in1(:,9)+1.0).*6.27e1)./log(2.0)-(in1(:,14).*log(2.514300107956375e-5./in1(:,14)+1.0).*2.700000000000003)./log(2.0)-(in1(:,23).*log(2.980398721805458e-4./in1(:,23)+1.0).*2.700000000000003)./log(2.0)-(in1(:,154).*log(2.536734576857251e-5./in1(:,154)+1.0).*6.27e1)./log(2.0)-(in1(:,57).*log(1.090879257850063e-5./in1(:,57)+1.0).*6.27e1)./log(2.0)-(in1(:,76).*log(1.129706506851571e-4./in1(:,76)+1.0).*2.700000000000003)./log(2.0)-(in1(:,109).*log(2.558079924151623e-5./in1(:,109)+1.0).*6.27e1)./log(2.0)-(in1(:,75).*log(3.654172086781249e-4./in1(:,75)+1.0).*2.700000000000003)./log(2.0)-(in1(:,109).*log(2.558079904087554e-5./in1(:,109)+1.0).*2.700000000000003)./log(2.0)-(in1(:,22).*log(2.283723279692574e-5./in1(:,22)+1.0).*6.27e1)./log(2.0)-(in1(:,36).*log(4.870005063321393e-4./in1(:,36)+1.0).*2.700000000000003)./log(2.0)-(in1(:,95).*log(7.962761634294468e-5./in1(:,95)+1.0).*6.27e1)./log(2.0)-(in1(:,68).*log(2.783681217497318e-4./in1(:,68)+1.0).*6.27e1)./log(2.0)-(in1(:,70).*log(1.70845387062621e-3./in1(:,70)+1.0).*2.700000000000003)./log(2.0)-(in1(:,87).*log(9.406921605195156e-4./in1(:,87)+1.0).*2.700000000000003)./log(2.0)-(in1(:,26).*log(1.12864534571323e-5./in1(:,26)+1.0).*2.700000000000003)./log(2.0)-(in1(:,38).*log(7.306094355426823e-5./in1(:,38)+1.0).*2.700000000000003)./log(2.0)-(in1(:,28).*log(1.795141894854763e-4./in1(:,28)+1.0).*2.700000000000003)./log(2.0)-(in1(:,26).*log(1.128645347997953e-5./in1(:,26)+1.0).*6.27e1)./log(2.0)-(in1(:,57).*log(1.090879065416532e-5./in1(:,57)+1.0).*2.700000000000003)./log(2.0)-(in1(:,27).*log(9.043708046285206e-5./in1(:,27)+1.0).*2.700000000000003)./log(2.0)-(in1(:,65).*log(8.073642583575628e-4./in1(:,65)+1.0).*6.27e1)./log(2.0)-(in1(:,92).*log(3.039633915786994e-5./in1(:,92)+1.0).*2.700000000000003)./log(2.0)-(in1(:,96).*log(7.394537855022456e-4./in1(:,96)+1.0).*2.700000000000003)./log(2.0)-(in1(:,153).*log(8.012810723870263e-5./in1(:,153)+1.0).*6.27e1)./log(2.0)-(in1(:,31).*log(1.248232405768023e-4./in1(:,31)+1.0).*6.27e1)./log(2.0)-(in1(:,151).*log(3.718852719025231e-5./in1(:,151)+1.0).*6.27e1)./log(2.0)-(in1(:,120).*log(1.374120958261478e-4./in1(:,120)+1.0).*6.27e1)./log(2.0)-(in1(:,168).*log(8.60915874098138e-5./in1(:,168)+1.0).*6.27e1)./log(2.0)-(in1(:,76).*log(1.129706507149941e-4./in1(:,76)+1.0).*6.27e1)./log(2.0)-(in1(:,60).*log(1.107546343089073e-5./in1(:,60)+1.0).*6.27e1)./log(2.0)-(in1(:,135).*log(1.432099253515767e-4./in1(:,135)+1.0).*6.27e1)./log(2.0)-(in1(:,106).*log(7.186634489993739e-5./in1(:,106)+1.0).*2.700000000000003)./log(2.0)-(in1(:,33).*log(6.11109985272239e-4./in1(:,33)+1.0).*2.700000000000003)./log(2.0)-(in1(:,177).*log(3.152473575227821e-5./in1(:,177)+1.0).*2.700000000000003)./log(2.0)-(in1(:,146).*log(2.462395702655356e-4./in1(:,146)+1.0).*2.700000000000003)./log(2.0)-(in1(:,5).*log(6.511066818378382e-5./in1(:,5)+1.0).*6.27e1)./log(2.0)-(in1(:,157).*log(1.285490118876367e-4./in1(:,157)+1.0).*6.27e1)./log(2.0)-(in1(:,89).*log(2.149568190248988e-4./in1(:,89)+1.0).*2.700000000000003)./log(2.0)-(in1(:,39).*log(7.712972009042298e-4./in1(:,39)+1.0).*6.27e1)./log(2.0)-(in1(:,148).*log(9.926594772798826e-6./in1(:,148)+1.0).*2.700000000000003)./log(2.0)-(in1(:,51).*log(2.44335853972425e-4./in1(:,51)+1.0).*6.27e1)./log(2.0)-(in1(:,135).*log(1.432099251104773e-4./in1(:,135)+1.0).*2.700000000000003)./log(2.0)-(in1(:,1).*log(1.592791694124719e-4./in1(:,1)+1.0).*6.27e1)./log(2.0)-(in1(:,2).*log(3.976340549497248e-7./in1(:,2)+1.0).*6.27e1)./log(2.0)-(in1(:,71).*log(5.16949011772525e-5./in1(:,71)+1.0).*6.27e1)./log(2.0)-(in1(:,103).*log(1.816960919178301e-4./in1(:,103)+1.0).*2.700000000000003)./log(2.0)-(in1(:,153).*log(8.012810721799162e-5./in1(:,153)+1.0).*2.700000000000003)./log(2.0)-(in1(:,31).*log(1.248232405766132e-4./in1(:,31)+1.0).*2.700000000000003)./log(2.0)-(in1(:,95).*log(7.962761632634943e-5./in1(:,95)+1.0).*2.700000000000003)./log(2.0)-(in1(:,177).*log(3.15247365894401e-5./in1(:,177)+1.0).*6.27e1)./log(2.0)-(in1(:,146).*log(2.462396542779665e-4./in1(:,146)+1.0).*6.27e1)./log(2.0)-(in1(:,59).*log(5.690307924246731e-4./in1(:,59)+1.0).*6.27e1)./log(2.0)-(in1(:,123).*log(4.41441858608037e-4./in1(:,123)+1.0).*6.27e1)./log(2.0)-(in1(:,75).*log(3.654178013425385e-4./in1(:,75)+1.0).*6.27e1)./log(2.0)-(in1(:,59).*log(5.690307884547468e-4./in1(:,59)+1.0).*2.700000000000003)./log(2.0)-(in1(:,160).*log(1.248055155948976e-3./in1(:,160)+1.0).*2.700000000000003)./log(2.0)-(in1(:,73).*log(4.615120659756858e-6./in1(:,73)+1.0).*2.700000000000003)./log(2.0)-(in1(:,130).*log(9.102200613061163e-6./in1(:,130)+1.0).*2.700000000000003)./log(2.0)-(in1(:,69).*log(3.547103802825236e-4./in1(:,69)+1.0).*2.700000000000003)./log(2.0)-(in1(:,84).*log(2.620542915143757e-4./in1(:,84)+1.0).*2.700000000000003)./log(2.0)-(in1(:,38).*log(7.306100014736255e-5./in1(:,38)+1.0).*6.27e1)./log(2.0)-(in1(:,164).*log(7.253294381388299e-5./in1(:,164)+1.0).*6.27e1)./log(2.0)-(in1(:,73).*log(4.615120983522106e-6./in1(:,73)+1.0).*6.27e1)./log(2.0)-(in1(:,169).*log(2.093498022392337e-4./in1(:,169)+1.0).*6.27e1)./log(2.0)-(in1(:,160).*log(1.248074458990539e-3./in1(:,160)+1.0).*6.27e1)./log(2.0)-(in1(:,120).*log(1.374120831903159e-4./in1(:,120)+1.0).*2.700000000000003)./log(2.0)-(in1(:,2).*log(3.976340448461962e-7./in1(:,2)+1.0).*2.700000000000003)./log(2.0)-(in1(:,55).*log(1.69583842010779e-4./in1(:,55)+1.0).*2.700000000000003)./log(2.0)-(in1(:,78).*log(3.700708059146551e-4./in1(:,78)+1.0).*2.700000000000003)./log(2.0)-(in1(:,124).*log(1.493669425823087e-4./in1(:,124)+1.0).*2.700000000000003)./log(2.0)-(in1(:,137).*log(5.321326078913253e-4./in1(:,137)+1.0).*2.700000000000003)./log(2.0)-(in1(:,180).*log(2.489140374246951e-4./in1(:,180)+1.0).*2.700000000000003)./log(2.0)-(in1(:,47).*log(2.007765642116442e-4./in1(:,47)+1.0).*6.27e1)./log(2.0)-(in1(:,10).*log(7.773708537473517e-6./in1(:,10)+1.0).*6.27e1)./log(2.0)-(in1(:,123).*log(4.414416056151271e-4./in1(:,123)+1.0).*2.700000000000003)./log(2.0)-(in1(:,92).*log(3.039634990991273e-5./in1(:,92)+1.0).*6.27e1)./log(2.0)-(in1(:,69).*log(3.547112562110829e-4./in1(:,69)+1.0).*6.27e1)./log(2.0)-(in1(:,86).*log(3.256307174410304e-5./in1(:,86)+1.0).*6.27e1)./log(2.0)-(in1(:,104).*log(4.669739409129287e-5./in1(:,104)+1.0).*2.700000000000003)./log(2.0)-(in1(:,99).*log(8.406741282930918e-5./in1(:,99)+1.0).*6.27e1)./log(2.0)-(in1(:,145).*log(2.62131948569829e-4./in1(:,145)+1.0).*6.27e1)./log(2.0)-(in1(:,60).*log(1.107546330203636e-5./in1(:,60)+1.0).*2.700000000000003)./log(2.0)-(in1(:,174).*log(1.505018202887781e-4./in1(:,174)+1.0).*2.700000000000003)./log(2.0)-(in1(:,27).*log(9.04370809390637e-5./in1(:,27)+1.0).*6.27e1)./log(2.0)-(in1(:,130).*log(9.102200613261273e-6./in1(:,130)+1.0).*6.27e1)./log(2.0)-(in1(:,72).*log(8.935993089324253e-6./in1(:,72)+1.0).*6.27e1)./log(2.0)-(in1(:,124).*log(1.493705004737316e-4./in1(:,124)+1.0).*6.27e1)./log(2.0)-(in1(:,164).*log(7.25329349290908e-5./in1(:,164)+1.0).*2.700000000000003)./log(2.0)-(in1(:,158).*log(8.221716446120684e-4./in1(:,158)+1.0).*2.700000000000003)./log(2.0)-(in1(:,158).*log(8.221716451343319e-4./in1(:,158)+1.0).*6.27e1)./log(2.0)-(in1(:,128).*log(5.401281926973628e-5./in1(:,128)+1.0).*2.700000000000003)./log(2.0)-(in1(:,23).*log(2.980398724789611e-4./in1(:,23)+1.0).*6.27e1)./log(2.0)-(in1(:,174).*log(1.50504874087289e-4./in1(:,174)+1.0).*6.27e1)./log(2.0)-(in1(:,32).*log(2.918025664553941e-5./in1(:,32)+1.0).*6.27e1)./log(2.0)-(in1(:,114).*log(1.136962927302141e-4./in1(:,114)+1.0).*6.27e1)./log(2.0)-(in1(:,154).*log(2.536734362833077e-5./in1(:,154)+1.0).*2.700000000000003)./log(2.0)-(in1(:,128).*log(5.401286334394613e-5./in1(:,128)+1.0).*6.27e1)./log(2.0)-(in1(:,21).*log(4.673615013499751e-5./in1(:,21)+1.0).*2.700000000000003)./log(2.0)-(in1(:,70).*log(1.708530984318943e-3./in1(:,70)+1.0).*6.27e1)./log(2.0)-(in1(:,106).*log(7.186635938960522e-5./in1(:,106)+1.0).*6.27e1)./log(2.0)-(in1(:,34).*log(1.873550783324951e-4./in1(:,34)+1.0).*6.27e1)./log(2.0)-(in1(:,84).*log(2.620545610936377e-4./in1(:,84)+1.0).*6.27e1)./log(2.0)-(in1(:,65).*log(8.073636689898464e-4./in1(:,65)+1.0).*2.700000000000003)./log(2.0)-(in1(:,68).*log(2.783681216061339e-4./in1(:,68)+1.0).*2.700000000000003)./log(2.0)-(in1(:,33).*log(6.111099903763513e-4./in1(:,33)+1.0).*6.27e1)./log(2.0)-(in1(:,21).*log(4.673615342732187e-5./in1(:,21)+1.0).*6.27e1)./log(2.0)-(in1(:,61).*log(9.114559633645742e-4./in1(:,61)+1.0).*2.700000000000003)./log(2.0)-(in1(:,55).*log(1.695838425758367e-4./in1(:,55)+1.0).*6.27e1)./log(2.0)-(in1(:,63).*log(9.322248199040759e-5./in1(:,63)+1.0).*2.700000000000003)./log(2.0)-(in1(:,63).*log(9.322248207922858e-5./in1(:,63)+1.0).*6.27e1)./log(2.0)-(in1(:,72).*log(8.93599303138855e-6./in1(:,72)+1.0).*2.700000000000003)./log(2.0)-(in1(:,1).*log(1.592791689012414e-4./in1(:,1)+1.0).*2.700000000000003)./log(2.0)-(in1(:,145).*log(2.621319462549545e-4./in1(:,145)+1.0).*2.700000000000003)./log(2.0)-(in1(:,103).*log(1.816960919424889e-4./in1(:,103)+1.0).*6.27e1)./log(2.0)-(in1(:,119).*log(6.720157169499005e-4./in1(:,119)+1.0).*6.27e1)./log(2.0)-(in1(:,19).*log(4.298551340774251e-4./in1(:,19)+1.0).*6.27e1)./log(2.0)-(in1(:,30).*log(1.905149359027724e-4./in1(:,30)+1.0).*2.700000000000003)./log(2.0)-(in1(:,117).*log(5.735376181156458e-5./in1(:,117)+1.0).*6.27e1)./log(2.0)-(in1(:,49).*log(1.867966529448703e-5./in1(:,49)+1.0).*6.27e1)./log(2.0)-(in1(:,147).*log(5.175910738214906e-5./in1(:,147)+1.0).*6.27e1)./log(2.0)-(in1(:,171).*log(5.345736855582846e-5./in1(:,171)+1.0).*6.27e1)./log(2.0)-(in1(:,5).*log(6.511066810885859e-5./in1(:,5)+1.0).*2.700000000000003)./log(2.0)-(in1(:,156).*log(5.473531387638728e-4./in1(:,156)+1.0).*6.27e1)./log(2.0)-(in1(:,10).*log(7.77370840804361e-6./in1(:,10)+1.0).*2.700000000000003)./log(2.0)-(in1(:,175).*log(7.862430970288111e-5./in1(:,175)+1.0).*2.700000000000003)./log(2.0)-(in1(:,114).*log(1.136962823443101e-4./in1(:,114)+1.0).*2.700000000000003)./log(2.0)-(in1(:,48).*log(4.906751287231519e-5./in1(:,48)+1.0).*2.700000000000003)./log(2.0)-(in1(:,94).*log(4.455056377225578e-5./in1(:,94)+1.0).*6.27e1)./log(2.0)-(in1(:,147).*log(5.175910055751504e-5./in1(:,147)+1.0).*2.700000000000003)./log(2.0)-(in1(:,156).*log(5.473529214539608e-4./in1(:,156)+1.0).*2.700000000000003)./log(2.0)-(in1(:,137).*log(5.321332334918264e-4./in1(:,137)+1.0).*6.27e1)./log(2.0)-(in1(:,99).*log(8.406741099696084e-5./in1(:,99)+1.0).*2.700000000000003)./log(2.0)-(in1(:,131).*log(6.584604328680697e-4./in1(:,131)+1.0).*6.27e1)./log(2.0)-(in1(:,86).*log(3.256307173618805e-5./in1(:,86)+1.0).*2.700000000000003)./log(2.0)-(in1(:,30).*log(1.905149676752631e-4./in1(:,30)+1.0).*6.27e1)./log(2.0)-(in1(:,87).*log(9.406921760100818e-4./in1(:,87)+1.0).*6.27e1)./log(2.0)-(in1(:,47).*log(2.007708704812767e-4./in1(:,47)+1.0).*2.700000000000003)./log(2.0)-(in1(:,34).*log(1.873544576329058e-4./in1(:,34)+1.0).*2.700000000000003)./log(2.0)-(in1(:,171).*log(5.345736813477682e-5./in1(:,171)+1.0).*2.700000000000003)./log(2.0)-(in1(:,169).*log(2.093495886752037e-4./in1(:,169)+1.0).*2.700000000000003)./log(2.0)-(in1(:,131).*log(6.584604313711503e-4./in1(:,131)+1.0).*2.700000000000003)./log(2.0)-(in1(:,133).*log(5.617103797100137e-4./in1(:,133)+1.0).*2.700000000000003)./log(2.0)-(in1(:,175).*log(7.862430992279681e-5./in1(:,175)+1.0).*6.27e1)./log(2.0)
Error in test_Lagrangian>@(c)objfun_AnonymousFunction(c)
Error in fmincon (line 536)
initVals.f = feval(funfcn{3},X,varargin{:});
Error in test_Lagrangian (line 219)
[c_opt,fval_c,flag_c] = fmincon(objfun_c,c0,A_c,b_c,[],[],lb_c,ub_c,[],opts);
Caused by:
Failure in initial objective function evaluation. FMINCON cannot continue.
However, if I use 'vars', {c} it works. But I don't know if it make sense or not.
Walter Roberson
on 23 Apr 2019
What size is your c0 ?
fmincon reshapes the vector of values into the same shape as c0 before passing it in. If your c0 is a 2D array then 'vars', {c} should be fine.
Walter Roberson
on 23 Apr 2019
Yes, 'vars', {c} should work for that.
More Answers (1)
Susan
on 22 Apr 2019
@ Walter, I am trying to write-down the following linear constraint according to the way you taught me above.
sum_{m} sum_{i} p(i, j,j,k,m) <=P_{k, j} for all k = 1: K and j = 1 : J
m = 1: M and i = 1 : I and P_{k, j} is given and fixed for each specific k and j
I wrote this constraint in the format of
A(something,:) = [zeros(1, SOMETHING), ones(1, I), zeros(1,SOMETHINGELSE)];
b(something) = P_{k,j};
However, I wasn't able to find a specific relationship between the rows of A.
What I found is sth like
A(1, :) = [ones(1, I) zeros(1, (J*J*K -1)*I) ones(1, I) zeros(1, (J*J*K -1)*I) ]
A(2, :) = [zeros(1,K) ones(1, I) zeros(1,(J*J*K -1)*I) ones(1, I) zeros(1,(J*J*K -1)*I) zeros(1,(J*J*K -1)*I -K)]
the pattern "ones(1, I) zeros(1, (J*J*K -1)*I) ones(1, I) zeros(1, (J*J*K -1)*I) " is repeated in all rows but I wasn't able to figure out what is the formulation of the begining zeros(1, SOMETHING), and correspondingly the zeros(1,SOMETHINGELSE) in order to write matrix A.
Could you please let me know what would be the format of A? Thank you so much in advance.
2 Comments
Walter Roberson
on 22 Apr 2019
Use the blkdiag() method I posted as "easier way of generating this". It generates the entire A and b matrix in a small number of lines.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)